하려는 쿼리고
from 안에 있는건 성공
전체 다돌리면 error
===================================================================
select sum(SKT) SV, 0 SW, sum(KTF) KV, 0 KW, sum(LGT) LV, 0 LW from
(select sum(st_0) - sum(st_1) SKT, 0 KTF, 0 LGT from mpg_stat_cust where telco_gb = 'S'
union
select 0 SKT, sum(st_0) - sum(st_1) KTF, 0 LGT from mpg_stat_cust where telco_gb = 'K'
union
select 0 SKT ,0 KTF, sum(st_0) - sum(st_1) LGT from mpg_stat_cust where telco_gb = 'L')
===================================================================
★from 절뒤부터는 적용됨
db2 => (select sum(st_0) - sum(st_1) SKT, 0 KTF, 0 LGT from mpg_stat_cust where telco_gb = 'S' union select 0 SKT, sum(st_0) - sum(st_1) KTF, 0 LGT from mpg_stat_cust where telco_gb = 'K' union select 0 SKT ,0 KTF, sum(st_0) - sum(st_1) LGT from mpg_stat_cust where telco_gb = 'L')
SKT KTF LGT
----------- ----------- -----------
- 0 0
0 - 0
0 0 -
3 record(s) selected.
★그러나 from 앞을붙이면 안됌!!!
db2 => select sum(SKT) SV, 0 SW, sum(KTF) KV, 0 KW, sum(LGT) LV, 0 LW from (select sum(st_0) - sum(st_1) SKT, 0 KTF, 0 LGT from mpg_stat_cust where telco_gb = 'S' union select 0 SKT, sum(st_0) - sum(st_1) KTF, 0 LGT from mpg_stat_cust where telco_gb = 'K' union select 0 SKT ,0 KTF, sum(st_0) - sum(st_1) LGT from mpg_stat_cust where telco_gb = 'L')
SQL0104N An unexpected token "" was found following ")". Expected tokens may
include: "AS". SQLSTATE=42601
db2 =>
★-로 인한 에러같아서 COALESCE()함수 적용
===================================================================
select sum(SKT) SV, 0 SW, sum(KTF) KV, 0 KW, sum(LGT) LV, 0 LW from
(select COALESCE(sum(st_0) - sum(st_1),0) SKT, 0 KTF, 0 LGT from mpg_stat_cust where telco_gb = 'S'
union
select 0 SKT, COALESCE(sum(st_0) - sum(st_1),0) KTF, 0 LGT from mpg_stat_cust where telco_gb = 'K'
union
select 0 SKT ,0 KTF, COALESCE(sum(st_0) - sum(st_1),0) LGT from mpg_stat_cust where telco_gb = 'L')
===================================================================
db2 => (select COALESCE(sum(st_0) - sum(st_1),0) SKT, 0 KTF, 0 LGT from mpg_stat_cust where telco_gb = 'S' union select 0 SKT, COALESCE(sum(st_0) - sum(st_1),0) KTF, 0 LGT from mpg_stat_cust where telco_gb = 'K' union select 0 SKT ,0 KTF, COALESCE(sum(st_0) - sum(st_1),0) LGT from mpg_stat_cust where telco_gb = 'L')
SKT KTF LGT
----------- ----------- -----------
0 0 0
1 record(s) selected.
★다시 전체 실행 error!!!
db2 => select sum(SKT) SV, 0 SW, sum(KTF) KV, 0 KW, sum(LGT) LV, 0 LW from (select COALESCE(sum(st_0) - sum(st_1),0) SKT, 0 KTF, 0 LGT from mpg_stat_cust where telco_gb = 'S' union select 0 SKT, COALESCE(sum(st_0) - sum(st_1),0) KTF, 0 LGT from mpg_stat_cust where telco_gb = 'K' union select 0 SKT ,0 KTF, COALESCE(sum(st_0) - sum(st_1),0) LGT from mpg_stat_cust where telco_gb = 'L')
SQL0104N An unexpected token "" was found following ")". Expected tokens may
include: "AS". SQLSTATE=42601
|