sql - Need to solve Group by -
select wk_nbr,region_cd,plant_cd, pos_gap_1day from(select wk_nbr,region_cd,plant_cd, round((case when sum(gap_1day)>0 sum(gap_1day) else 0 end ),2) pos_gap_1day table group wk_nbr,region_cd,plant_cd)
in above query problem facing pos_gap_1day
should sum positive numbers in column above query not give right answer since check sum(gap_1day)>0
.
the problem need group wk_nbr
,region_cd
,plant_cd
.
please suggest
try change
round((case when sum(gap_1day)>0 sum(gap_1day) else 0 end ),2) pos_gap_1day
to
round(sum(case when sign(gap_1day) > 0 gap_1day else 0 end), 2) pos_gap_1day
Comments
Post a Comment