原数据(tableAAA):
BUG_LEVEL | VOLTAGE_LEVEL | C |
1 | 小计 | 96 |
1 | 110kV | 19 |
1 | 220kV | 74 |
1 | 500kV | 3 |
2 | 小计 | 48 |
2 | 110kV | 18 |
2 | 500kV | 3 |
2 | 220kV | 27 |
3 | 小计 | 35 |
3 | 110kV | 7 |
3 | 500kV | 10 |
3 | 220kV | 18 |
合计 | 小计 | 179 |
合计 | 110kV | 44 |
合计 | 220kV | 119 |
合计 | 500kV | 16 |
经过:
SELECT DECODE(S.BUG_LEVEL,'1', 'YBQX',
'2', 'ZYQX',
'3', 'JJQX',
'HJ') BUG_LEVEL,
SUM(DECODE(S.VOLTAGE_LEVEL, '500kV', C)) V_500KV_T,
SUM(DECODE(S.VOLTAGE_LEVEL, '220kV', C)) V_220KV_T,
SUM(DECODE(S.VOLTAGE_LEVEL, '110kV', C)) V_110KV_T,
SUM(DECODE(S.VOLTAGE_LEVEL, '小计', C)) FLHZ
FROM tableAAA S
GROUP BY S.BUG_LEVEL
转换为行形式:
BUG_LEVEL | V_500KV_T | V_220KV_T | V_110KV_T | FLHZ |
YBQX | 3 | 74 | 19 | 96 |
ZYQX | 3 | 27 | 18 | 48 |
JJQX | 10 | 18 | 7 | 35 |
HJ | 16 | 119 | 44 | 179 |