*!*
姓名
年
月
产量
*!*
李明 2010
8
200
*!*
李明 2010
9
200
*!*
张三 2010
8
300
*!*
张三 2010
9
400
*!*
张三 2010
10
500
*!*
张三 2010
11
600
*!*
张三 2010
12
700
*!*
张三 2011
1
800
*!*
张三 2011
2
900
*!*
表2
*!*
姓名
年
月
1
2
3
4
5
6
7
8
9
10
11
12
*!*
李明 2010
200
200
*!*
张三 2010
300
400
500
600
700
*!*
张三 2011
800
900
CLOSE ALL
CREATE CURSOR tmp (姓名 c(8),年 n(4),月 n(2),产量 n(6))
INSERT INTO tmp VALUES ('李明',2010, 8,200)
INSERT INTO tmp VALUES ('李明',2010, 9,200)
INSERT INTO tmp VALUES ('张三',2010, 8,300)
INSERT INTO tmp VALUES ('张三',2010, 9,400)
INSERT INTO tmp VALUES ('张三',2010,10,500)
INSERT INTO tmp VALUES ('张三',2010,11,600)
INSERT INTO tmp VALUES ('张三',2010,12,700)
INSERT INTO tmp VALUES ('张三',2011, 1,800)
INSERT INTO tmp VALUES ('张三',2011, 2,900)
SET ENGINEBEHAVIOR
70
SELECT 姓名,年,;
SUM(iIF(月=1,产量,0)) m01,;
SUM(IIF(月=2,产量,0)) m02,;
SUM(IIF(月=3,产量,0)) m03,;
SUM(IIF(月=4,产量,0)) m04,;
SUM(IIF(月=5,产量,0)) m05,;
SUM(IIF(月=6,产量,0)) m06,;
SUM(IIF(月=7,产量,0)) m07,;
SUM(IIF(月=8,产量,0)) m08,;
SUM(IIF(月=9,产量,0)) m09,;
SUM(IIF(月=10,产量,0)) m10,;
SUM(IIF(月=11,产量,0)) m11,;
SUM(IIF(月=12,产量,0)) m12;
FROM tmp;
GROUP BY 1,2