例如:
SELECT COUNT(*),SUM(PRI)
FROM TEST
WHERE TEST_NO = 'a'
AND NAME LIKE ‘TE%';
SELECT COUNT(*),SUM(PRI)
FROM TEST
WHERE TEST_NO = 'b'
AND NAME LIKE ‘TE%';
--DECODE轻松实现行转列
SELECT COUNT(DECODE(TEST_NO,0020,'A',NULL)) COUNT_0020,
COUNT(DECODE(TEST_NO,0030,'A',NULL)) COUNT,_0030
SUM(DECODE(TEST_NO,0020,PRI,NULL)) PRI_0020,
SUM(DECODE(TEST_NO,0030,PRI,NULL)) PRI_0030
FROM EMP WHERE NAME LIKE ‘TE%';
SELECT COUNT(*),SUM(PRI)
FROM TEST
WHERE TEST_NO = 'a'
AND NAME LIKE ‘TE%';
SELECT COUNT(*),SUM(PRI)
FROM TEST
WHERE TEST_NO = 'b'
AND NAME LIKE ‘TE%';
--DECODE轻松实现行转列
SELECT COUNT(DECODE(TEST_NO,0020,'A',NULL)) COUNT_0020,
COUNT(DECODE(TEST_NO,0030,'A',NULL)) COUNT,_0030
SUM(DECODE(TEST_NO,0020,PRI,NULL)) PRI_0020,
SUM(DECODE(TEST_NO,0030,PRI,NULL)) PRI_0030
FROM EMP WHERE NAME LIKE ‘TE%';