Oracle行转列
先贴上代码,有时间再整理。
Select w_name,max(decode(ut.attdate,to_date('2010-12-01','yyyy-MM-dd'),ut.tgname,null)) d1
,max(decode(ut.attdate,to_date('2010-12-02','yyyy-MM-dd'),ut.tgname,null)) d2
,max(decode(ut.attdate,to_date('2010-12-03','yyyy-MM-dd'),ut.tgname,null)) d3
,max(decode(ut.attdate,to_date('2010-12-04','yyyy-MM-dd'),ut.tgname,null)) d4
From
(
Select w.*,t.tgname,t.attdate From
MDC_TEAMGROUPUSER tw
Left Join mdc_workerinfo w
On w.id = tw.userid
Left Join MDC_TEAMGROUPINFO t
On tw.teamgroupid = t.recordid
Where
t.machineid = 'b4595d48-7c6a-4cbf-81cf-ce7d1185baa5'
) ut
Group by ut.w_name
,max(decode(ut.attdate,to_date('2010-12-02','yyyy-MM-dd'),ut.tgname,null)) d2
,max(decode(ut.attdate,to_date('2010-12-03','yyyy-MM-dd'),ut.tgname,null)) d3
,max(decode(ut.attdate,to_date('2010-12-04','yyyy-MM-dd'),ut.tgname,null)) d4
From
(
Select w.*,t.tgname,t.attdate From
MDC_TEAMGROUPUSER tw
Left Join mdc_workerinfo w
On w.id = tw.userid
Left Join MDC_TEAMGROUPINFO t
On tw.teamgroupid = t.recordid
Where
t.machineid = 'b4595d48-7c6a-4cbf-81cf-ce7d1185baa5'
) ut
Group by ut.w_name