SQLServer2008 行转列

with a as(
select *,row_number() over(partition by hyid order by jp desc) rowid
from rtc)
select a.hyid,
	max(case when a.rowid=1 then a.mc END) mc,
	max(case when a.rowid=1 then a.jp END) jp,

	max(case when a.rowid=2 then a.mc END) mc2,
	max(case when a.rowid=2 then a.jp END) jp2,

	max(case when a.rowid=3 then a.mc END) mc3,
	max(case when a.rowid=3 then a.jp END) jp3,

	max(case when a.rowid=4 then a.mc END) mc4,
	max(case when a.rowid=4 then a.jp END) jp4,

	max(case when a.rowid=5 then a.mc END) mc5,
	max(case when a.rowid=5 then a.jp END) jp5
from a
group by a.hyid

 

posted @ 2015-02-28 13:53  emmy  阅读(572)  评论(0编辑  收藏  举报