SQL报表横向显示,交叉报表显示 (1)

用DECODE 或用交叉报表实现报表横向显示


CREATE TABLE LL (ART_NO VARCHAR2(3),NAME VARCHAR2(4),SALES VARCHAR2(4));

INSERT INTO LL VALUES(101,'A1',200);

INSERT INTO LL VALUES(102,'B1',400);

INSERT INTO LL VALUES(103,'C1',600);

INSERT INTO LL VALUES(104,'D1',800);

COMMIT

SELECT NO,MAX(N101) AS "101",MAX(N102) AS "102",MAX(N103) AS "103",MAX(N104) AS "104"
FROM (
SELECT 1 NO,
DECODE(ART_NO,'101',NAME,NULL) AS "N101",
DECODE(ART_NO,'102',NAME,NULL) AS "N102",
DECODE(ART_NO,'103',NAME,NULL) AS "N103",
DECODE(ART_NO,'104',NAME,NULL) AS "N104"
FROM LL
UNION
SELECT 2 NO,
DECODE(ART_NO,'101',SALES,NULL) AS "N101",
DECODE(ART_NO,'102',SALES,NULL) AS "N102",
DECODE(ART_NO,'103',SALES,NULL) AS "N103",
DECODE(ART_NO,'104',SALES,NULL) AS "N104"
FROM LL
)
GROUP BY NO

posted on 2013-03-07 16:18  陈惟鲜的博客  阅读(177)  评论(0编辑  收藏  举报

导航