Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何仅在列的计数超过一定数量时检索数据_Mysql_Sql - Fatal编程技术网

Mysql 如何仅在列的计数超过一定数量时检索数据

Mysql 如何仅在列的计数超过一定数量时检索数据,mysql,sql,Mysql,Sql,这是我的问题 SELECT news.*, count(followers.artist_id) as followers FROM news INNER JOIN followers ON news.artist_id = followers.artist_id GROUP BY followers.artist_id ORDER BY followers DESC 所以我现在得到的所有新闻都是按某个艺术家的粉丝数量排序的 我想做的是,如果粉丝超过一定数量,比如说10个,我只想检索新

这是我的问题

SELECT news.*, count(followers.artist_id) as followers 
FROM news 
INNER JOIN followers ON news.artist_id = followers.artist_id 
GROUP BY followers.artist_id 
ORDER BY followers DESC
所以我现在得到的所有新闻都是按某个艺术家的粉丝数量排序的

我想做的是,如果粉丝超过一定数量,比如说10个,我只想检索新闻

所以我试着加入一个where子句

WHERE followers > 10
但是我得到一个错误,where子句中没有这样的列

我能做些什么来实现这一点?我可以制作一个包含跟随者计数的假列吗

干杯

试试这个:

SELECT news.*, x.[followers]
FROM news
INNER JOIN (
    SELECT news.id, Count(followers.id) as [followers]
    FROM news 
    INNER JOIN followers ON news.artist_id = followers.artist_id 
    GROUP BY news.id
    HAVING Count(followers.id) > 10) as x on x.id = news.id

我假设两个表(新闻和关注者)都有唯一标识行的id列。

使用
HAVING
。例如,
分组依据。。。。拥有数量(追随者.艺术家id)>10….