ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 时间是没有值时取0用什么函数.(是外连接的问题)

时间是没有值时取0用什么函数.(是外连接的问题)

原创 Linux操作系统 作者:zhangweicai74 时间:2008-05-24 09:41:55 0 删除 编辑
昨天SQL优化的续集,不过这次不是优化的问题,而是时间没有值的时候取0用什么函数.
(可能是个极其简单的问题,但本人确实不知道)
select /*+ no_index(ith1) */ ip.part_no, max(ith1.dated) indate,max(ith2.dated) outdate
from ifsapp.inventory_transaction_hist_tab ith1,
     ifsapp.inventory_transaction_hist_tab ith2,
     ifsapp.inventory_part_tab ip
where ith1.part_no(+) = ip.part_no
   and ith2.part_no(+)=ip.part_no
   and ith1.contract = ip.contract
   and ith2.contract = ip.contract
   and ith1.transaction_code = 'OOREC'
   and ith2.transaction_code = 'OESHIP'
   and ith1.date_applied >= to_date('2007-1-1', 'yyyy-mm-dd')
   and ith2.date_applied >= to_date('2007-1-1', 'yyyy-mm-dd')
   and ip.contract = 'SKY'
   and ip.sk_part_category_db = '1'
group by ip.part_no

问题:
有可能ith1.dated有值时,ith2.dated没有值.反之亦然。上记语句会漏掉其中一个时间没有值的这一部分。
  只取出两者都有值的部分.如果是数字,可用NVL(),时间用什么?(排除转换为数字再转换回时间)
   当然DECODE也可以,不过肯定会影响性能.
有请

[ 本帖最后由 zhangweicai74 于 2008-5-23 11:13 编辑 ]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12391917/viewspace-310109/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: SQL优化
请登录后发表评论 登录
全部评论

注册时间:2007-12-27

  • 博文量
    35
  • 访问量
    78476