[英]How to count rows that have the same values in two columns and return only rows where count<N(SQL)?
regarding that question: How to count rows that have the same values in two columns (SQL)? 关于这个问题: 如何计算两列中具有相同值的行(SQL)?
is there a way to return only the rows where the count is < 3? 有没有办法只返回计数<3的行?
+-----+-----+-----+
| A | B |count|
+=====+=====+=====+
| 1 | 3 | 2 |
+-----+-----+-----+
| 4 | 2 | 1 |
+-----+-----+-----+
The HAVING
clause HAVING
子句
SELECT ...
FROM ...
WHERE ...
GROUP BY whatever
HAVING count(*) <3
Just add the condition in the HAVING
clause 只需在HAVING
子句中添加条件即可
SELECT colName, COUNT(*)
FROM tableName
GROUP BY colName
HAVING COUNT(*) < 3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.