2017-06-09 40 views
-1

考慮以下問題:我們有3個表,解決在二次時間?

  1. 劇院(theatre_Id,thatre_name)
  2. ShowTime中(showTimeId,theatre_Id,movie_id)
  3. 電影(movie_id,MOVIE_NAME) 現在同一部電影的名字可以也有不同的movieId的依賴卷軸。

例如:[1,哈利·波特],[2,哈利·波特],[3,卡爾盜]

這個問題是前回答。使用不帶邏輯的方面相同的公式,但使用 How to solve the following nested query?

回答

1

EXISTS代替

select distinct movie_name 
from Movies m 
where EXISTS (
    select 1 
    from ShowTime t 
    where m.movie_id = t.movie_id 
    group by movie_id 
    having count(distinct theatre_Id) = (select count(*) from Theatre))