[[DB2]] | [[Category:SQL]]
===[[R]]OLLUPROLLUP===
*グループごとのサマリーを作成
SELECT t.name AS tour_name,
c.name AS county_name,
COUNT(*) AS falls_count
F[[R]]OM FROM upfall u INNE[[R]] INNER JOIN trip t
ON u.id = t.stop
INNE[[R]] INNER JOIN county c
ON u.county_id = c.id
G[[R]]OUP GROUP BY [[R]]OLLUPROLLUP(t.name, c.name);
TOU[[R]]_NAME TOUR_NAME COUNTY_NAME FALLS_COUNT
---------- ----------- ----------------------
M-28 Alger 3
c.name county_name,
COUNT(*) AS falls_count
F[[R]]OM FROM upfall u INNE[[R]] INNER JOIN trip t
ON u.id = t.stop
INNE[[R]] INNER JOIN county c
ON u.county_id = c.id
WHE[[R]]E WHERE t.name = 'Munising' G[[R]]OUP GROUP BY CUBE(t.name, c.name);
TOU[[R]]_NAME TOUR_NAME COUNTY_NAME FALLS_COUNT
---------- ----------- ----------------------
6
Munising Alger 6
===G[[R]]OUP GROUP BY で有用な関数=======G[[R]]OUPINGGROUPING( column )====*CUBE, [[R]]OLLUPの結果が ROLLUPの結果が NULL の場合、1を返す、そうでない場合、0を返す