日期:2014-05-17  浏览次数:20398 次

帮忙写条sql语句
select * from info1 where id1 in (select id1 from info2 GROUP BY id1)

现在我要的结果是:(select id1 from info2 GROUP BY id1)查出的数量多少来排序

例如:id1在info2里面:id1=1的有5条;id1=2的有10条
  select * from info1查出的结果是以 数量多的排序出来,既id2的数据排前面


------解决方案--------------------
加一个条件

select * from info1 where id1 in (select id1 from info2 GROUP BY id1 order by id1 desc)
------解决方案--------------------
select * from info1 inner join (select id ,count(*) as cnt from info2 group by id1) tbl2
where info1.id = tbl2.id order by tbl2.cnt desc
------解决方案--------------------
SQL code


SELECT ID1 FROM  Info2 GROUP BY ID1 ORDER BY COUNT(ID1) DESC

------解决方案--------------------
用分组 或者排序试下