我有以下sql查询:
select count(tu.authorID) as c,t.tweettext,tu.name
from tweet t
inner join tweet_user tu on t.authorid=tu.authorid
where count(tu.authorID)>=5;
但似乎内部联接不适用于本案例中的位置,我收到以下错误:
Error Code: 1111. Invalid use of group function 0.062 sec
有谁知道我的问题是什么,或者我怎么做?
答案 0 :(得分:1)
答案 1 :(得分:1)
使用HAVING
而不是WHERE
作为COUNT
等汇总功能:
SELECT t.tweettext,tu.name, count(tu.authorID) as c
FROM tweet t inner join tweet_user tu on t.authorid=tu.authorid
HAVING count(tu.authorID)>=5
尽管mySQL
可以取消GROUP BY
,但您可能也可以包含GROUP BY
,但我认为您不需要tweettext
?
SELECT tu.name, count(tu.authorID) as c
FROM tweet t inner join tweet_user tu on t.authorid=tu.authorid
GROUP BY tu.name
HAVING count(tu.authorID)>=5