好的,我相信我以前做过类似的事,但不记得我是怎么做的。
四处搜索给了我类似的答案,但没有解决我的问题。
Ex1,此查询没问题:
SELECT col1, count(*) as col3
FROM db.table
WHERE col2 = 0 group by col1
Ex2,但我需要所有col3大于1的地方,所以我试过:
Select *
FROM
(SELECT col1, count(*) as col3
FROM db.table
WHERE col2 = 0 group by col1)
WHERE col3 > 1;
# Not working
Ex3,我不知道为什么,但这似乎有效:
SELECT col1, count(*) as col3
FROM db.table
WHERE col2 = 0
GROUP BY col1
HAVING count(*) > 1;
答案 0 :(得分:1)
好的,当我从Mysql读取错误消息时,我刚刚回答了我自己的问题。
Select *
FROM
(SELECT col1, count(*) as col3
FROM db.table
WHERE col2 = 0 group by col1) temp
WHERE col3 > 1;
我错过了别名。