How to solve the following case?

泄露秘密 提交于 2019-12-13 09:25:13

问题


Consider the following question: We have 3 tables,

1. Theatre  ( theatre_Id, thatre_name )
2. ShowTime ( showTimeId,  theatre_Id, movie_id )
3. Movies   ( movie_id, movie_name )

Now same movie name can also have different movieId's sort of dependent on the reel.

Eg: [1, HarryPotter], [2, HarryPotter], [3, Pirates of Carr]

Now we need to find movie name which has showtime on all theatre locations ? Is it nested correlated query ?


回答1:


If you better phrase the question:

What are the names of movies whose theatre list is the same size as the number of theatres?

you get the query:

select distinct movie_name
from Movies m
where movie_id in (
    select movie_id
    from ShowTime
    group by movie_id
    having count(distinct theatre_Id) = (select count(*) from Theatre))


来源:https://stackoverflow.com/questions/44424707/how-to-solve-the-following-case

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!