我有一张桌子programparticipants.我目前成功查询ID在哪里count(name) > 1.我现在需要的是查询属于那些ID的名称count(name) > 1.
例如,当前返回的数据结果:
ID count(name)
1 2
3 4
4 3
Run Code Online (Sandbox Code Playgroud)
例如,需要的数据结果:
ID name
1 nm1
1 nm3
3 nm2
3 nm3
3 nm4
3 nm7
4 nm5
4 nm8
4 nm9
Run Code Online (Sandbox Code Playgroud)
小智 51
select count(id), name
from programparticipants
group by name
having count(id) > 1
Run Code Online (Sandbox Code Playgroud)
你可以用这个:
SELECT
(SELECT name FROM participants WHERE id=p.participantid) AS name
FROM
programparticipants AS p
WHERE
.... (the part where you find count(name)>1)
Run Code Online (Sandbox Code Playgroud)