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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -