表的结构 temp_fwgps070426
scph gxdm sl
1 01 100
1 02 100
1 03 100
2 01 100
2 03 100
3 01 100
3 02 100
3 03 100
希望得到的数据格式
scph 01 02 03
1 100 100 100
2 100 0 100
3 100 100 100我是这样写的:
set @sql = 'select scph'
select @sql = @sql + ',sum(case gxdm when '''+gxdm+''' then sl else 0 end) ['+pxms+']'
from (select distinct pxdm,pxms from temp_fwgps070426) as a
select @sql = @sql + ' into temp_fwgps070426 from temp_fwgps070426 group by scph '
exec(@sql)
这样写可以得到数据,但是有个问题,导出来的数据可能是
scph 02 01 03
或者
scph 01 03 02我希望在导成横向的时候 按照 scph 01 02 03 的顺序排列
scph gxdm sl
1 01 100
1 02 100
1 03 100
2 01 100
2 03 100
3 01 100
3 02 100
3 03 100
希望得到的数据格式
scph 01 02 03
1 100 100 100
2 100 0 100
3 100 100 100我是这样写的:
set @sql = 'select scph'
select @sql = @sql + ',sum(case gxdm when '''+gxdm+''' then sl else 0 end) ['+pxms+']'
from (select distinct pxdm,pxms from temp_fwgps070426) as a
select @sql = @sql + ' into temp_fwgps070426 from temp_fwgps070426 group by scph '
exec(@sql)
这样写可以得到数据,但是有个问题,导出来的数据可能是
scph 02 01 03
或者
scph 01 03 02我希望在导成横向的时候 按照 scph 01 02 03 的顺序排列
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货