2014-02-26 73 views
0

我有結果的數量問題上運行此查詢後,我得到:SQL查詢:預計不止一個結果,但只有一個返回

SELECT g.genre_name, 
     count(distinct(d.director_id)) 
    FROM genre g, 
     director d, 
     movie m 
WHERE g.genre_id=m.genre_id 
     AND m.director_id=d.director_id; 

表及其鍵:

  1. genre(genre_id, genre_name)
  2. movie(genre_id, director_id)
  3. director(director_id)

任何人都可以幫忙嗎?提前致謝!

回答

0

嘗試添加GROUP BY

SELECT g.genre_name, 
     count(distinct(d.director_id)) 
    FROM genre g, 
     director d, 
     movie m 
    WHERE g.genre_id=m.genre_id 
     AND m.director_id=d.director_id 
GROUP BY g.genre_name; 
+0

是啊,這工作。謝謝! –