我有一個電影數據庫,其中一個表格用於演員,另一個用於電影,我創建了第三個表格以在電影中添加演員partecipation。我添加了一個領域「明星」來區分不是主要演員的主要演員。 我希望根據演員的重要性和「星星」總數創建一個列表順序。由第三個表中的在線訂購表
SELECT a.id, a.name, COUNT(p.star) AS star
FROM actors a
JOIN playing p, movies m
WHERE p.id_actor = a.id
AND p.id_movie = m.id
AND p.star =1
GROUP BY p.star
ORDER BY p.star DESC;
ACTORS
+----+---------+
| id | name |
+----+---------+
| 1 | actor01 |
| 2 | actor02 |
| 3 | actor03 |
+----+---------+
MOVIES
+----+----------+
| id | title |
+----+----------+
| 1 | movie01 |
| 2 | movie02 |
| 3 | movie03 |
+----+----------+
PLAYING
+----------+----------+-------+------+
| id_movie | id_actor | char | star |
+----------+----------+-------+------+
| 1 | 1 | char1 | 0 |
| 1 | 2 | char2 | 1 |
| 2 | 3 | char3 | 1 |
+----------+----------+-------+------+
我需要輸出一樣:
+----------+--------------+
| actor | protagonist |
+----------+--------------+
| actor01 | 2 times |
| actor02 | 3 times |
+----------+--------------+
請加您的預期輸出 –
不要混合隱式(逗號)連接和顯式J OIN語法。事實上,根本不要使用逗號加入 - 至少在你真的知道你在做什麼之前。 – Strawberry
@Strawberry即使你知道你在做什麼 – Bohemian