我在这里撞墙挡住我的头。刚开始学习SQL,我有三个这样的表:
表CD(num,producer,band_name,cd_name)
表BandSingers(band_name,singer_id)
表歌手(身份证,姓名)
我正在试图弄清楚如何通过乐队获得出现在大多数Cds上的歌手的名字,而我不知道如何去做,但这就是我所拥有的:
select id, name
from Singer, BandSingers
where Singer.id = (select singer_id
from BandSingers
where band_name = (select band_name
from CD
where max(count(band_name))));
认为我离开了,但感谢帮助,谢谢!
答案 0 :(得分:0)
试试这个家伙
B
答案 1 :(得分:0)
请尝试改为
Select Top 1 c.id, c.[name], Count(a.band_name)
From CD a
left join BandSingers b on b.band_name = a.band_name
left join Singer c on c.id = b.singer_id
Group by c.id, c.[name]
Order by 3 desc
答案 2 :(得分:-1)
想通了,我将语法操作为'group by'和'having',然后就解决了。