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