???????????????????з???
??????????飺????????????????????????ν??к????
????????GROUP BY???
????????

 

SELECT column1??column2
FROM table1??table2
WHERE conditions
GROUP BY column1??column2
ORDER BY column1??column2;

????1?????麯??
???????????麯??—???????GROUP BY??????????л???????—????AVG??MAX??MIN??SUM??COUNT??
????2??????е???????з???
??????????????????????????е????(?????SELECT????????б?)??????GROUP BY??????????????????SELECT????????????????????GROUP BY???
????????????????з????????????ε??????????SELECT???????δ????????
????3????????????????????
????SELECT????????GROUP BY?????????????????????????????е???α????????GROUP BY?????????????????
?????????????????????λ??NULL?????????????????λ??NULL????
????4???????????????????
??????ORDER BY????????GROUP BY????????????????????????????
????????GROUP BY??ORDER BY
????ORDER BY?????????????????????????????GROUP BY???????????????????????????????????????GROUP BY??????????ORDER BY???????????????????
???????GROUP BY????????????????????????
????1?????б???е??????????????α???????GROUP BY?????
????2???????????????????????????GROUP BY?????????????????б?????
???????CUBE??ROLLUP???
????ROLLUP????
????GROUP BY ROLLUP(ordered column list of grouping sets)
????MySQL ROLLUP????
????GROUP BY order column list of grouping sets WITH ROLLUP
????ROLLUP????????????
????1???????????????????????????
????2???????????????????????????б??е???????Σ??????????ν??з???????????????С????????????У??????????λ?????NULL???
????3???????????????????????е????λ?t????NULL???
????CUBE????
????GROUP BY CUBE(column list of grouping sets)
????CUBE?????SQL Server??Oracle?ж?????????MySQL?в????????
????CUBE????????????
????1??????????б??е???????ν?????????????????????????????????????????    2????CUBE?????????????????
?????塢HAVING???
????HAVING?????????GROUP BY????????ORDER BY???????

 

????
SELECT column1??column2
FROM table1??table2
WHERE contidions
GROUP BY column1??column2
HAVING conditions
ORDER BY column1??column2;