group by having count() 用法
group by
语句用于结合聚合函数,根据一个或多个列对结果集进行分组。
语法:
select column1, column2, … column_n, aggregate_function (expression)
from tables
where predicates
group by column1, column2, … column_n;
having
下面是 HAVING 子句在 SELECT 查询中的位置:
SELECT
FROM
WHERE
GROUP BY
HAVING
ORDER BY
HAVING 子句必须放置于 GROUP BY 子句后面,ORDER BY 子句前面,下面是 HAVING 子句在 SELECT 语句中基础语法:
SELECT column1, column2
FROM table1, table2
WHERE [ conditions ]
GROUP BY column1, column2
HAVING [ conditions ]
ORDER BY column1, column2
having count(*)
统计某一列的数据
查询分组后msg大于2的id和数量