我有A,B两个表如下A表: B表:
part qty date part sqty date
001 10 070601 001 6 070602
001 14 070602 001 8 070605
001 8 070605 002 10 070602
现在我要把以上两表关连后筛选了如下的数据
part qty date
001 10 070601 如果a.part=b.part 但a.date没有等于b.date的
值时qty的值就为a.qty
001 20 070602 如果a.part=b.part 并且a.date=b.date
001 16 070605 这时qty的值为a.qty+b.sqty
请问这样该如何写SQL语句
part qty date part sqty date
001 10 070601 001 6 070602
001 14 070602 001 8 070605
001 8 070605 002 10 070602
现在我要把以上两表关连后筛选了如下的数据
part qty date
001 10 070601 如果a.part=b.part 但a.date没有等于b.date的
值时qty的值就为a.qty
001 20 070602 如果a.part=b.part 并且a.date=b.date
001 16 070605 这时qty的值为a.qty+b.sqty
请问这样该如何写SQL语句
解决方案 »
- 求PL SQL基础资料,就要语法方面的,能进行PL SQL编程
- 各位高手,小弟求书
- XMLType不能insert, For security reasons, ftp and http access over XDB repository is not allowed on server side
- 请高手帮帮忙,在Oracle里面怎样通过储存过程解析XMLTYPE数据类型的文件(急)
- 如何让新建的用户只有select权限和调用存储过程的权限
- oracle备份的问题?
- 求SQL语句
- ORACLE在域中机器中无法安装???
- 基础问题,大虾帮忙!
- 非法关机导致9i数据库无法使用
- oracle中sum函数得出的结果与jsp中显示的不同
- 求一段简单的SQL文~~
////在AS 这位置 提示缺少关键字
(select PART_NO PART_NO_1,sum(QUANTITY) QTYOUT,DATE_APPLIED from INVENTORY_TRANSACTION_HIST2
where (LOCATION_NO='CYLBSJJ' or LOCATION_NO='CYLKSJJ' or (TRANSACTION_CODE='INVSCRAP' and (LOCATION_NO='DHBS' OR LOCATION_NO='DHKS'))) AND DIRECTION='-' and part_no like 'A22%'
and (to_char(DATE_APPLIED,'yyyy-mm-dd') > '2007-06-28' and to_char(DATE_APPLIED,'yyyy-mm-dd') <='2007-07-10') and TRANSACTION_CODE in ('INVM-ISS','INVSCRAP')
GROUP BY PART_NO,DATE_APPLIED) q,
(select i.part_no,sum(t.qty_scrapped) qtyscr,i.arrival_date date_applied from purchase_receipt_new i,purchase_receipt_scrap t
where i.part_no like 'A22%' and (to_char(i.arrival_date,'yyyy-mm-dd') > '2007-06-28' and to_char(i.arrival_date,'yyyy-mm-dd') <= '2007-07-10')
and i.order_no=t.order_no and i.line_no=t.line_no and i.release_no=t.release_no and i.receipt_no=t.receipt_no GROUP BY i.PART_NO,i.arrival_date) p
where q.part_no_1=p.part_no
请问哪里错了???
from
(select temp4.PART part4, temp4.QTY qty4, temp4.DATE1 date4
from temp4
union allselect temp5.PART part5, temp5.sQTY qty5, temp5.DATE1 date5
from temp5) tempgroup by part4, date4
select TableTemp.PART4 ,sum(TableTemp.QTY4), date4
from
(select temp4.PART part4, temp4.QTY qty4, temp4.DATE1 date4 from Table1
union all
select temp5.PART part4, temp5.SQTY qty4, temp5.DATE1 date4 from Table2
) TableTemp
group by part4, date4
这样能清楚点?
正确
还是没满足a.part=b.part这个条件?
你如果真的发现了group by 如果不能满足分组
那么你可以宣称你发现了无与伦比的BUG, 恭喜你!