2012-08-16 71 views
1

我的查詢是:mysql命令

select a from b where c in (
    select d from e where f in (
     select f from e where d=100) 
    and e!=100 group by e order by count(e) desc 
    ) 
) 

此查詢將輸出結果,我想要什麼,但我想通過這個子查詢

select d from e where f in (
    select f from e where d=100) 
and e!=100 group by e order by count(f) desc 

基本上我想通過訂購來訂購吧計數(f)

我該如何實現主查詢從子查詢中獲取ID,但它不會按子查詢順序排列它們

回答

1

從你添加的SQL中,我得到這樣的東西:

SELECT e1.d 
    FROM e e1, 
     (SELECT * 
      FROM e 
     WHERE d = 100) e2 
WHERE e1.f = e2.f AND e1.e != 100 
GROUP BY e1.e 
ORDER BY COUNT (e2.f)