2012-01-30 58 views
1

我有一個表COSTS包含PART_NO,ITEM_COSTS,COST_DATE僅減少1個表中日期的差異數據Oracle SQL

如何從不同日期扣除成本?這基本上是我啥子想

Select PART_NO 
, ITEM_COSTS 
WHERE COST_DATE = DATE_A 
AND PART_NO = B 

和減去從

Select PART_NO 
, ITEM_COSTS 
WHERE COST_DATE = DATE_B 
AND PART_NO = B 

回答

1
SELECT a.part_no, 
     b.item_costs - a.item_costs as diff 
FROM costs a 
    JOIN costs b ON a.part_no = b.part_no 
WHERE a.cost_date = date_a 
    AND b.cost_date = date_b 
+0

感謝。這給了我所需要的。我是一個自學成才的新手,很少想到這樣的加入! – 2012-01-30 15:41:08