你好(我是PHP的新手),
我无法弄清楚我想要制作的子查询的语法,这是查询:
SELECT * FROM show_episode, shows, show_episode_airdate, show_moyenne
WHERE season = 1 AND episode = 1
AND shows.imdb_id = show_episode.imdb_id_show
AND show_episode_airdate.episode_id = show_episode.episode_id
AND show_moyenne.show_id = shows.id
AND show_episode_airdate.airdate < '2013-07-12'
ORDER BY show_episode_airdate.airdate DESC LIMIT 10
一旦完成,我想通过show_moyenne.moyenne对这10个选定行进行排序:
SELECT * (FROM show_episode, shows, show_episode_airdate, show_moyenne
WHERE season = 1 AND episode = 1
AND shows.imdb_id = show_episode.imdb_id_show
AND show_episode_airdate.episode_id = show_episode.episode_id
AND show_moyenne.show_id = shows.id
AND show_episode_airdate.airdate < '2013-07-12'
ORDER BY show_episode_airdate.airdate DESC LIMIT 10)
* ORDER BY show_moyenne.moyenne DESC
哪个不正确,任何人都可以告诉我正确的方法吗?
谢谢,任何帮助表示赞赏!
答案 0 :(得分:2)
Select * from
(SELECT * FROM show_episode, shows, show_episode_airdate, show_moyenne
WHERE season = 1 AND episode = 1
AND shows.imdb_id = show_episode.imdb_id_show
AND show_episode_airdate.episode_id = show_episode.episode_id
AND show_moyenne.show_id = shows.id
AND show_episode_airdate.airdate < '2013-07-12'
ORDER BY show_episode_airdate.airdate DESC LIMIT 10) as j
order by j.moyenne DESC
我希望这可以提供一些帮助。
答案 1 :(得分:1)
SELECT x.*
FROM
( SELECT *
FROM show_episode e
JOIN shows s
ON s.imdb_id = e.imdb_id_show
JOIN show_episode_airdate a
ON a.episode_id = e.episode_id
JOIN show_moyenne m
ON m.show_id = s.id
WHERE season = 1
AND episode = 1
AND a.airdate < '2013-07-12'
ORDER
BY a.airdate DESC
LIMIT 10
) x
ORDER
BY moyenne;