all groups > sql server programming > march 2005 >
You're in the

sql server programming

group:

sum() in query


sum() in query TJS
3/14/2005 11:17:10 PM
sql server programming: Without the sum function, this query runs fine.

SELECT usereventid, sum(cost) as cost_summary
FROM vw_PlayerList
ORDER BY Name

when I add a sum function to this query it throws an error which says:

"Column 'vw_PlayerList.UserEventID' is invalid in the select list because it
is not contained in an aggregate function and there is no GROUP BY clause.
Column name 'vw_PlayerList.Name' is invalid in the ORDER BY clause because
it is not contained in an aggregate function and there is no GROUP BY
clause."


how can I add a simple sum function to the above query ???

Re: sum() in query David Portas
3/14/2005 11:29:44 PM
You haven't explained exactly what you want to sum. Here's a guess:

SELECT usereventid, name,
SUM(cost) AS cost_summary
FROM vw_PlayerList
GROUP BY usereventid, name
ORDER BY name

If you need more help, please refer to the following article which
explains the best way to post your question:

http://www.aspfaq.com/etiquette.asp?id=5006

--
David Portas
SQL Server MVP
--
Re: sum() in query TJS
3/15/2005 1:24:15 AM
do me a favor Portas, and just put me in your block list

Re: sum() in query David Portas
3/15/2005 4:53:06 AM
[quoted text, click to view]

Meaning what? Did my query help?

--
David Portas
SQL Server MVP
--
Re: sum() in query Raymond D'Anjou
3/15/2005 9:15:30 AM
My guess is that you've made yourself an enemy David.
http://www.developersdex.com/sql/message.asp?p=581&r=3868401

[quoted text, click to view]

AddThis Social Bookmark Button