database - duplicated values in SQL code -
i have below sql code -
select distinct opr, case when timestamp '201302%' ((sum (charge / power (10, decimals)) on (partition opr) * 1.15306)) when timestamp '201303%' ((sum (charge / power (10, decimals)) on (partition opr)* 1.14979)) else 0 end exr in group opr, timestamp, (charge / power (10, decimals))
and expect receive value - 1080.104079
however, gives me 2 values -
this value 1079.459992 get, because exr has been swept, wrong, charge 'feb' should multiplied on exr 'feb'
could please me correct code, can receive true value, 1080.104079.
if need 1 result, try moving case logic sum function itself:
select opr, sum(case when timestamp '201302%' ((charge / power (10, decimals)) * 1.15306) when timestamp '201303%' ((charge / power (10, decimals)) * 1.14979) else 0 end) exr in group opr having opr = 'dom';
part of problem seems you're grouping multiple columns, yet selecting 1 or two. if group opr column only, should 1 row 'dom'.
Comments
Post a Comment