select A.cusdate, A.qnt1-isnull(B.trans_ut,0) as utut, A.org_gw-isnull(B.trans_gw,0) as gwgw
from
(select idx,prod,case when customsdate='' then 'N' else 'Y' end cusdate, qnt1,isnull(CAST(gw AS float),0) as org_gw
from as_pulp where unload='군산항' and customsdate <>'null') A
left outer join
(select pulp_idx,sum(ut) as trans_ut , sum(CAST(gw AS float)) as trans_gw from as_trans group by pulp_idx) B
on A.idx = B.pulp_idx
결과
---------------------------------------
cusdate utut gwgw
---------------------------------------
Y 96.0 48.1920
N 277.0 139.054
N 294.0 147.639
Y 38.0 19.0760
Y 400.0 200.800
cusdate를 group by 해서 utut, gwgw 각각의 합을 구하고 싶습니다
도와주세요~~~ |