当前位置: 代码迷 >> Sql Server >> group by order by解决思路
  详细解决方案

group by order by解决思路

热度:27   发布时间:2016-04-27 20:35:50.0
group by order by
select   lianxi_dw.dw   as   dw1,count(lianxi.id)   as   num   from   lianxi_dw   left   join   lianxi   on   lianxi_dw.dw=lianxi.dw   group   by   lianxi_dw.dw   order   by   lianxi_dw.uid
不行!
去掉order   by可以查询出数据只是顺序乱了
请帮忙写下可以排序的

------解决方案--------------------
select lianxi_dw.uid,lianxi_dw.dw as dw1,
count(lianxi.id) as num
from lianxi_dw left join lianxi
on lianxi_dw.dw=lianxi.dw
group by lianxi_dw.dw ,lianxi_dw.uid
order by lianxi_dw.uid

------解决方案--------------------
select lianxi_dw.dw as dw1,count(lianxi.id) as num from lianxi_dw left join lianxi on lianxi_dw.dw=lianxi.dw group by lianxi_dw.dw order by min(lianxi_dw.uid)

  相关解决方案