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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i didn't find any issues
ASKER
Thanks angelIII that works great !
one thing through I dont really understand the code, could explain it if possible ?
thanks
again
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.
the outer query uses that data, and just orders by the field tpoints you generated in the inner query.