sql - Aggregate function not giving sum -
i have query:
select o.idorder, sum(case when cast(isnull(ama.freeshiping, 0) int) = 0 - 1000 else cast(isnull(ama.freeshiping, 0) int) end) freeshiping orderdetail od, amazonsku ama, orders o, tempprintrecords tmp o.idorder = od.idorder , o.idcustomer = ama.idcustomer , od.sku = ama.sku --and od.idorder=350184 , od.idorder = tmp.idorder , ama.freeshiping != 0 group o.idorder
result:
here have 0 , null in ama.freeshiping
basically column bit , contains 0 , 1. if 0 found make -1000 identify idorder
having 0 or null freeshipping
but it's not giving proper sum, should give result in -ve each column.
this expression in where
clause:
and ama.freeshiping != 0
only chooses values "1". remove if want see other values.
you should learn use proper join
syntax. if used join
keyword, of conditions in on
clauses, , where
condition might have been easier spot.
Comments
Post a Comment