内部查询字段的mysql顺序

时间:2012-08-16 23:06:38

标签: mysql subquery

我的查询是:

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

基本上我想通过count(f)来订购

如何实现主查询从子查询中获取id但不会根据子查询对它们进行排序

1 个答案:

答案 0 :(得分: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)