how to sum up data base on location
Posted on 2011-05-09
I have a table that has fields (Sku, Location_id, Quantity). I would like sum up the Quantity values for two unique locations_id and leave it alone if it equals anything else.
sku Location_id Qty
23452 1001 10
23452 1002 20
23452 1003 70
Sum up the values in locations 1001 & 1002
select sku, case when location_id=1001 or location_id=1002 then 'East' else 'West' end as LOC
case when location_id=1001 or location_id=1002 sum(quantity) else quantity end as QTY_1
from tablex group by sku, location_id
I'm still getting values for each location for some reason, I think the group by is getting me.