n********6 发帖数: 1511 | 1 (如果题目出错了,请高人指教)
作cross tab query, 也叫pivot table。
有以下table:
MONTH, PRODUCT1, PRODUCT2
1, 3, 2
2, 4, 2
3, 5, 8
4, 9, 5
...
12, 40, 34
要求:转换一下矩阵,并作SUM(),变成如下:
PRODUCT, QUARTER1, QUARTER2, QUARTER3, QUARTER4
PRODUCT1 21, ...
PRODUCT2 17, ... | g*****a 发帖数: 47 | 2 select 'PRODUCT1', (select SUM(PRODUCT1) from M where M.MONTH>=1&M.MONTH<=3)
, (select SUM(PRODUCT1) from M where M.MONTH>=4&M.MONTH<=6), (select SUM(
PRODUCT1) from M where M.MONTH>=7&M.MONTH<=9), (select SUM(PRODUCT1) from M
where M.MONTH>=10&M.MONTH<=11)
UNION
select 'PRODUCT2', (select SUM(PRODUCT2) from M where M.MONTH>=1&M.MONTH<=3)
..... |
|