我想获得具有或具有相同成员的乐队名称对(时间段并不重要,只是成员计数)。我需要从表ARTIST和ARTIST_RELATION中获得此信息。这是表的定义:
我知道当我显示| band1_members INTERSECT band2_members |时就足够了= | band1_members | = | band2_members | (这些集合具有相同数量的元素)
我尝试使用INTERSECT运算符,但是它似乎对我不起作用(这可能是最好的解决方案,但我无法实现)。第二个想法是使用SELF JOIN并遍历所有对。但是它并没有在15分钟内完成,因此我将其停止(ARTIST_RELATION表包含大约15000个元组)。第二个想法(我知道在这里我只是显示乐队的ID而不是名称,但这不是问题所在):
select t3.id1,t3.id2
from (select distinct t1.id as id1,t2.id as id2 ,t2.summe as sum_both
from (select id, count(*) as summe
from artist join artist_relation
on artist.id=artist1
where artist.type='Group' and artist_relation.type='member of band'
group by id) t1,
(select id, count(*) as summe
from artist join artist_relation
on artist.id=artist1
where artist.type='Group' and artist_relation.type='member of band'
group by id) t2
where t1.id<t2.id and t1.summe=t2.summe) as t3
where (select count(*)
from (select artist0
from artist_relation
where artist1=t3.id1 and type='member of band'
intersect
select artist0
from artist_relation
where artist1=t3.id2 and type='member of band') as t4)=t3.sum_both
如果我知道如何在GROUP BY内部进行相交(这里:将一个乐队的人与另一个乐队的人相交),我将无法解决