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