GROUP BY 分组子句
SELECT p_id,COUNT(*) AS n_p
FROM p
GROUP BY p_id
计算每一个id的数目
HAVING过滤分组
SELECT p_id,COUNT(*) AS n_p
FROM p
GROUP BY p_id
HAVING COUNT(*)>=2
也可使用WHERE过滤
ORDER BY:对输出进行排序
GROUP BY:对行分组,单输出可能不是分组的顺序
GROUP BY 分组子句
SELECT p_id,COUNT(*) AS n_p
FROM p
GROUP BY p_id
计算每一个id的数目
HAVING过滤分组
SELECT p_id,COUNT(*) AS n_p
FROM p
GROUP BY p_id
HAVING COUNT(*)>=2
也可使用WHERE过滤
ORDER BY:对输出进行排序
GROUP BY:对行分组,单输出可能不是分组的顺序