Two Ways To Rollup
June 16, 2015 Ted Holt
In Three Powerful SQL Words, I showed how to enhance summary queries with aggregate values over subsets of grouping columns. Today I continue that discussion by showing the two syntaxes of rollup and illustrating the difference between them. First, assume a table of accounting transactions. select department, account, amount from xacts2 order by 1, 2 DEPARTMENT ACCOUNT AMOUNT 1 10 200.00 1 10 250.00 1 30 300.00 2 10 125.00 2 20 175.00 2 20 225.00 Here’s a typical summary query using the familiar GROUP BY clause. select department, account, sum(amount) as tamt from xacts2 group by department, account |