SQL Query for Roll Up Totals

  • I wish to get in one single query Roll up Total of Amount from the folowing structures

    Table MGroup

    Fields GroupCode, GroupName, Amount

    Table mLedger

    Fields LedgerCode, LedgerName, GroupCode, Amount

     

     

     

     

  • something like this probably....cannot test...

    select G.GroupCode, sum(G.amount)+ max(L.amount) as totalAmount
    from MGroup G
    inner join 
    (select GroupCode, sum(amount) as amount from MLedger group by Groupcode)L 
    on
    G.GroupCode = L.GroupCode
    group by G.GroupCode
    







    **ASCII stupid question, get a stupid ANSI !!!**

  • If you change the last line to "group by G.GroupCode WITH ROLLUP", you'll get an extra row with the grand total for Amount (and a NULL for GroupCode).  Is that what you're looking for?

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply