oracle查询结果的行转列

想把结果的日期给弄成横排。所以就这样弄了。

select t.DXID AS 姓名,
sum(decode(t.CJSJ,'2019-05-01',RCYL,null))怪事,
sum(decode(t.CJSJ,'2019-05-02',RCYL,null))数字,
sum(decode(t.CJSJ,'2019-05-03',RCYL,null))为啥
from JCCDJNHRB t group by DXID order by DXID desc

 

再加一句

 

SELECT a.dxid,
sum(decode(a.CJSJ,'2019-05-01',RCYL,null))怪事,
sum(decode(a.CJSJ,'2019-05-02',RCYL,null))数字,
sum(decode(a.CJSJ,'2019-05-03',RCYL,null))为啥

from JCCDJNHRB a, dbaa061 b, DBBA021 c
where cjsj <= to_date('2019-05-03', 'yyyy-mm-dd ')
and cjsj >= to_date('2019-05-01', 'yyyy-mm-dd ')
and a.DWDM = '011101'
and a.dwdm = b.dwdm
and a.dxid = c.dxid
group by a.dxid order by a.dxid asc

posted @ 2019-07-25 17:02  南国之恋  阅读(2102)  评论(1编辑  收藏  举报