1. We have moved to a new forum! There may be a few things not working properly so please let us know if you find a bug. Remember to use the bbCode [ sql ] tag for SQL statements.

displaying a group by and grand total all on one line?

Discussion in 'SQL - Questions and Answers' started by Mike, Jun 30, 2006.

  1. Mike Guest

    Dialect: MS SQL
    I have a group by query which displays the total of each item. I also need to retrieve the grand total. I need to be able to display everything on one line
  2. Josh Dunlavy Guest

    Dialect: Oracle
    Below is more conceptual than actual code since I'm in a big rush right now, but I believe the quickest way to obtain results for you would be a subselect. Using a subselect would allow you total without grouping by all the other columns that would force the group by.

    SELECT sum(TABLE1.COLUMN1), TABLE1.INDEXCOLUMN, TABLE1.SOMEOTHERDATA, TABLE2.GRANDTOTAL
    FROM TABLE1,
    ( SELECT sum(TABLE1.COLUMN1) AS "GRANDTOTAL",
    FROM TABLE1 ) TABLE2
    WHERE...
    GROUP BY TABLE1.INDEXCOLUMN, TABLE1.SOMEOTHERDATA, null AS GRANDTOTAL

Share This Page