How do you sum a column, then sum a row?

  • 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?

  • use the rollup option on the group by statement

  • 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?

  • 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]

  • OK, I had tried that before but must have mangled my statement,

    that works just fine, thanks.

  • 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