时间:2021-07-01 10:21:17 帮助过:8人阅读
SELECT * FROM CUST_BANK_INFO
查询结果如下:
--DELETE FROM CUST_BANK_INFO DROP TABLE Mapping; CREATE TABLE Mapping ( CN_NAME VARCHAR(100), Code_L VARCHAR(10), Code_N VARCHAR(10) ) INSERT INTO Mapping values(‘理财‘,‘MT01‘,‘BANK_01‘); INSERT INTO Mapping values(‘理财‘,‘MT05‘,‘BANK_01‘); INSERT INTO Mapping values(‘贷款‘,‘MT02‘,‘BANK_02‘); INSERT INTO Mapping values(‘贷款‘,‘MT06‘,‘BANK_02‘); INSERT INTO Mapping values(‘存款‘,‘MT03‘,‘BANK_03‘); INSERT INTO Mapping values(‘存款‘,‘MT07‘,‘BANK_03‘); INSERT INTO Mapping values(‘教育储蓄‘,‘MT04‘,‘BANK_04‘); INSERT INTO Mapping values(‘教育储蓄‘,‘MT08‘,‘BANK_04‘); SELECT CUST_ID, CUST_NAME, BANK_NO, BANK, max(CASE WHEN B.Code_N=‘BANK_01‘ THEN MONEY ELSE ‘0‘ END) AS 理财, max(CASE WHEN B.Code_N=‘BANK_02‘ THEN MONEY ELSE ‘0‘ END) AS 贷款, max(CASE WHEN B.Code_N=‘BANK_03‘ THEN MONEY ELSE ‘0‘ END) AS 存款, max(CASE WHEN B.Code_N=‘BANK_04‘ THEN MONEY ELSE ‘0‘ END) AS 教育储蓄 FROM CUST_BANK_INFO A LEFT JOIN MAPPING B ON A.MONEY_TYPE_NO=B.Code_L group by CUST_ID,CUST_NAME,BANK,BANK_NO
查询结果如下:
DB2行转列(多维度)
标签: