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