2012-08-16 69 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)