Oracle查询问题

时间:2010-08-08 04:37:06

标签: sql oracle plsql

请告诉我为什么此查询无法合作。他们分开工作:

(  (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))

1 个答案:

答案 0 :(得分: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