关于这个问题: How to count rows that have the same values in two columns (SQL)?
有没有办法只返回计数为<的行。 3?
+-----+-----+-----+
| A | B |count|
+=====+=====+=====+
| 1 | 3 | 2 |
+-----+-----+-----+
| 4 | 2 | 1 |
+-----+-----+-----+
答案 0 :(得分:1)
HAVING
子句
SELECT ...
FROM ...
WHERE ...
GROUP BY whatever
HAVING count(*) <3
答案 1 :(得分:1)
只需在HAVING
子句中添加条件
SELECT colName, COUNT(*)
FROM tableName
GROUP BY colName
HAVING COUNT(*) < 3