Link to home
Start Free TrialLog in
Avatar of djpazza
djpazza

asked on

How do I order my sql select query by the result of the sum?

I have an sql statement that I want to order by points but I can not get it to work

I'm using asp, vbscript

code:

SELECT *,(SELECT SUM(points)
FROM teams
WHERE teams.teamid = users.id) AS Tpoints FROM Users

when I try :

SELECT *,(SELECT SUM(points)
FROM teams
WHERE teams.teamid = users.id) AS Tpoints FROM Users
ORDER BY Tpoints

I get an error 'Too few parametera' Expected 1
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i didn't find any issues
Avatar of djpazza
djpazza

ASKER

Thanks angelIII that works great !

one thing through I dont really understand the code, could explain it if possible ?

thanks
again
the inner query returns the data you want, only the order by is "missing"

the outer query uses that data, and just orders by the field tpoints you generated in the inner query.