按查询/ Mysql子查询的结果排序

按查询/ Mysql子查询的结果排序

问题描述:

Hi there (I'm new to PHP),

I can't quite figure out the syntax of a subquery I'm trying to make, this is the query:

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

Once this was done, I wanted to order those 10 selected rows by show_moyenne.moyenne with something like that:

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

Which is not correct, anybody can show me the right way to do this ?

Thanks, any help appreciated!

你好(我是PHP的新手), p>

我可以 我正在弄清楚我正在尝试制作的子查询的语法,这是查询: p>

  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&lt;  '2013-07-12'
ORDER BY show_episode_airdate.airdate DESC LIMIT 10 
  code>  pre> 
 
 

完成后,我想通过show_moyenne.moyenne订购这10个选定的行 有类似的东西: p>

  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&lt;'2013-07-12'
ORDER BY show_episode_airdate.airdate DESC LIMIT 10)
 * ORDER BY show_moyenne.moyenne DESC \  n  code>  pre> 
 
 

哪个不正确,有人可以告诉我正确的方法吗? p>

谢谢,任何帮助表示赞赏! div>

 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;

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

I hope this can be of some help.