在 MySQL GROUP BY 子句中使用多列有什么意义?
通过在 GROUP BY 子句中指定多列,我们可以将结果集拆分为更小的组。在 GROUP BY 子句中指定的列越多,组就会越小。
示例
mysql> Select designation, YEAR(Doj), count(*) from employees GROUP BY designation, YEAR(DoJ); +-------------+-----------+----------+ | designation | YEAR(Doj) | count(*) | +-------------+-----------+----------+ | Asso.Prof | 2013 | 1 | | Asst.Prof | 2015 | 1 | | Asst.Prof | 2016 | 1 | | Prof | 2009 | 2 | | Prof | 2010 | 1 | +-------------+-----------+----------+ 5 rows in set (0.00 sec)
广告