October 23, 2008 at 2:06 pm
I can sum columns like so:
SELECT SUM(A), SUM(B), SUM(C) FROM TABLE
but I then then to sum these fields like:
SELECT SUM(SUM(A), SUM(B), SUM(C)) FROM TABLE
Could someone give me the correct syntax please?
October 23, 2008 at 2:10 pm
use the rollup option on the group by statement
October 23, 2008 at 2:36 pm
That looks like it'll get me what I want but I'm still not getting the syntax,
my problem is that I only have the columns being returned that
I want to aggregate, i.e. I only want to end up with one value when done,
so I need something like:
SELECT SUM(A), SUM(B), SUM(C) FROM TBL GROUP BY *** WITH ROLLUP
but I can't use GROUP BY ALL with ROLLUP, and I can't use a column name that is an aggregate,
(and I tried using '1', but that didn't work either).
Any ideas?
October 23, 2008 at 3:22 pm
If you mean, summing for all of the rows, without any group by, then the easiest way is:SELECT SUM(A), SUM(B), SUM(C), SUM(A)+SUM(B)+SUM(C) FROM TABLE
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
October 23, 2008 at 3:32 pm
OK, I had tried that before but must have mangled my statement,
that works just fine, thanks.
October 23, 2008 at 3:44 pm
Glad we could help.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply