体验新版 GitCode,发现更多精彩内容 >>
-- @author tungs1 -- @modified 2013-07-28 12:00:00 -- @created 2013-07-28 12:00:00 -- @description groupingfunction groupingfunc83.sql -- @db_name groupingfunction -- @executemode normal -- @tags groupingfunction -- order 1 SELECT GROUPING(sale.pn) as g1, SUM(sale.pn) as g2 FROM product, sale WHERE product.pn=sale.pn GROUP BY ROLLUP((sale.pn,product.pname,sale.pn)) ORDER BY g1,g2; g1 | g2 ----+------ 0 | 200 0 | 300 0 | 400 0 | 600 0 | 700 0 | 800 0 | 800 0 | 1000 1 | 4800 (9 rows)