groupingfunc162.ans 636 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
-- @author tungs1
-- @modified 2013-07-28 12:00:00
-- @created 2013-07-28 12:00:00
-- @description groupingfunction groupingfunc162.sql
-- @db_name groupingfunction
-- @executemode normal
-- @tags groupingfunction
SELECT sale.pn, GROUPING(sale.pn) + 1 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 |  1
 100 |  1
 200 |  1
 200 |  1
 300 |  1
 300 |  1
 400 |  1
 400 |  1
 500 |  1
 500 |  1
 600 |  1
 600 |  1
 700 |  1
 700 |  1
 800 |  1
 800 |  1
     |  2
     |  2
     |  2
     |  2
     |  2
     |  2
     |  2
(23 rows)