1
我使用下面的查詢標識類別中最受歡迎的男演員(topActor):我應該如何修改我的查詢
SELECT category_id AS cid,
(SELECT actor_id FROM
film_actor JOIN film_category
ON film_actor.film_id = film_category.film_id
WHERE category_id = cid
GROUP BY actor_id
ORDER BY COUNT(*) DESC
LIMIT 0,1) AS topActor
FROM film_actor JOIN film_category
ON film_actor.film_id = film_category.film_id
GROUP BY category_id
+-----+----------+
| cid | topActor |
+-----+----------+
| 1 | 50 |
| 2 | 150 |
| 3 | 17 |
| 4 | 86 |
| 5 | 196 |
| 6 | 48 |
| 7 | 7 |
| 8 | 79 |
| 9 | 164 |
| 10 | 68 |
| 11 | 27 |
| 12 | 108 |
| 13 | 105 |
| 14 | 107 |
| 15 | 83 |
| 16 | 44 |
+-----+----------+
16 rows in set (0.00 sec)
現在我需要獲得相應的演員的FIRST_NAME和姓氏演員,含actor_id,姓氏和姓氏。我知道如何使用PL/SQL或SAS來完成它,但我是MySQL的新手。請幫忙!謝謝。
而不是在'SELECT'子句中使用嵌套查詢 - 加入它 – zerkms 2014-11-03 07:43:50
請發佈一個sql filddle或atleast您的相關db結構。 – 2014-11-03 07:53:21