2010-08-08 149 views
0

請讓我知道爲什麼這個查詢不能一起工作。他們分別工作:Oracle查詢問題

( (select item_name, 
      sum(p_qty) 
     from stock 
    where p_date between '08/06/2010' and '08/07/2010' 
    group by item_name) - 
( select item_name, 
      sum(p_r_qty) 
     from stock 
    where p_r_date between '08/06/2010' and '08/07/2010' 
    group by item_name)) 
+2

我想幫忙,但你想完成什麼?示例數據和預期輸出請。 – 2010-08-08 04:46:52

+0

那是什麼'''你有?你想減去查詢嗎? – Kobi 2010-08-08 04:51:30

回答

4
select item_name, 
      sum(p_qty) , 
      sum(p_r_qty) 
     from stock 
    where p_date between '08/06/2010' and '08/07/2010' 
group by item_name 

這是你想要的嗎?

select item_name, 
      sum(p_qty)-sum(p_r_qty) 
     from stock 
    where p_date between '08/06/2010' and '08/07/2010' 
group by item_name 
+0

是的,謝謝大家 – 2010-08-08 04:52:38