Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个具有以下结构的 mysql InnoDB 表:
id artist_id
那里有很多条目,大多数artist_ids在那里有15次。但有些人只在那里两次。我需要得到那些。
我想出了以下方法,但无济于事:
SELECT artist_id FROM matches HAVING COUNT(artist_id)=2
它返回 0 行,尽管有些艺术家 ID 只出现在表中两次。我怎样才能得到它们?
你好, 我会用这个: SELECT artist_id,count(*) FROM matches GROUP BY artist_id HAVING COUNT(*)=2 因为HAVING是结果的过滤器。
SELECT artist_id,count(*) FROM matches GROUP BY artist_id HAVING COUNT(*)=2
HAVING
与您一起=2,您会发现恰好存在两次的那些。
=2
select artist_id, count(id) as num from matches group by artist_id having num = 2;