数据库请求
问题描述:
我想要做如下要求我的数据库:数据库请求
我寻找谁与他人担任男主角(作业)在10分钟的电影togehter工作人员。你有任何提示或建议,我该如何解决这个问题?
- PRODUCTION(生产,标题)
- MOVIE(生产 - >生产,型)
- 人(人,名称,实名,birth_country)WORKS(人 - >
- PERSON,生产 - >生产作业)
答
这似乎像这类问题更适合像的Neo4j图形数据库,但在这里是一个关系型SQL解决方案:
select w1.person as person1
, w2.person as person2
, count(w1.production) as joint_productions
from works w1
join works w2
on w1.production = w2.production
where w1.person != w2.person
group by w1.person, w2.person having count(w1.production) >= 10
order by w1.person, w2.person;
这显示了演员和他们在一起的电影数量。它包括的倒数,即
bill murray, dan ackroyd, 10
dan ackroyd, bill murray, 10
如果你只是想将一组名称,你可以这样做:
select distinct w1.person
from works w1
join works w2
on w1.production = w2.production
where w1.person != w2.person
group by w1.person, w2.person having count(w1.production) >= 10
order by w1.person;
答
我可能会发现没有一个子请求的解决方案。这是对的吗?
select w1.person as person1, w2.person as person2, p1.name , p2.name, count(w1.production) as joint_productions
from works w1 join works w2 on w1.production = w2.production
join person p1 on w1.person = p1.person
join person p2 on w2.person = p2.person
where w1.person != w2.person
group by w1.person, p1.name, p2.name, w2.person having count(w1.production)
>= 10 order by w1.person, w2.person
嗨Kahoona,你到目前为止尝试过什么? –