oracle行转列,单行!!!
zdmc zdz
--------------
DW成都
ND2008
KTXM南缘
GQ华油
XMLX清华
TKRQ2008-3-18 0:00:00
期望转成:
dw nd ktxm gq xmlx tkrq
----------------------------------
成都 2008 南缘 华油 清华 2008-3-18 0:00:00
[解决办法]
with t as(select 'DW' zdmc,'成都' zdz from dualunion allselect 'ND','2008' from dualunion allselect 'KTXM','南缘' from dualunion allselect 'GQ','华油' from dualunion allselect 'XMLX','清华' from dualunion allselect 'TKRQ','2008-3-18 0:00:00' from dual)SELECT max(DECODE(zdmc, 'DW', zdz)) DW, max(DECODE(zdmc, 'ND', zdz)) ND, max(DECODE(zdmc, 'KTXM', zdz)) KTXM, max(DECODE(zdmc, 'GQ', zdz)) GQ, max(DECODE(zdmc, 'XMLX', zdz)) XMLX, max(DECODE(zdmc, 'TKRQ', zdz)) TKRQ FROM TDW ND KTXM GQ XMLX TKRQ----------------- ----------------- ----------------- ----------------- ----------------- -----------------成都 2008 南缘 华油 清华 2008-3-18 0:00:00
[解决办法]
楼上最经典的行转列,百度导出都是
[解决办法]
一般做法就是一个一个判断
[解决办法]
测试数据:
CREATE TABLE T186( ZDMC VARCHAR2(20), ZDZ VARCHAR2(20));INSERT INTO T186 VALUES('DW', '成都');INSERT INTO T186 VALUES('ND', '2008');INSERT INTO T186 VALUES('KTXM', '南缘');INSERT INTO T186 VALUES('GQ', '华油');INSERT INTO T186 VALUES('XMLX', '清华');INSERT INTO T186 VALUES('TKPQ', '2008-3-18 0:00:00');