-- @author tungs1 -- @modified 2013-07-28 12:00:00 -- @created 2013-07-28 12:00:00 -- @description groupingfunction groupingfunc50.sql -- @db_name groupingfunction -- @executemode normal -- @tags groupingfunction -- order 1 SELECT GROUPING(product.pname) as g1, GROUPING(sale.pn) as g2 FROM product, sale WHERE product.pn=sale.pn GROUP BY GROUPING SETS (sale.pn, product.pname, sale.pn) ORDER BY g1,g2; g1 | g2 ----+---- 0 | 1 0 | 1 0 | 1 0 | 1 0 | 1 0 | 1 0 | 1 1 | 0 1 | 0 1 | 0 1 | 0 1 | 0 1 | 0 1 | 0 1 | 0 1 | 0 1 | 0 1 | 0 1 | 0 1 | 0 1 | 0 1 | 0 1 | 0 (23 rows)