首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

group by order by解决思路

2012-04-07 
group by order byselectlianxi_dw.dwasdw1,count(lianxi.id)asnumfromlianxi_dwleftjoinlianxionlianxi_d

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)

热点排行