Oracle sql with as

--with as 如果子查询很多,或者 "一个字段"需要用到子查询中的"多个字段"

with TT as(
select A.运单编号,
K.发件地 ,
(select 所属财务中心 from tab_营业网点表 c where A .目的网点=c.网点编号) as 目的地公司,
(select 所属财务中心 from tab_营业网点表 c where A .录入部门=c.网点编号) as 操作公司 ,
A.录入部门,
A.录入时间,
'午交接' as 交接
--'晚交接' as jiaojie
from 巴枪记录表 A left join tab_运单资料表 K on A.运单编号 = K.运单编号
where 扫描类型 in ('袋转','件转','离线件转','离线袋转')
and a.录入时间 between to_date('2015-05-27 08:00:00','yyyy-mm-dd hh24:mi:ss')
and to_date('2016-05-27 14:30:00','yyyy-mm-dd hh24:mi:ss')


),
TT_2 as(
select B.运单编号,B.录入部门
from TT left join 巴枪记录表 B on B.运单编号= TT.运单编号
where 扫描类型 in ('袋到','件到') and B.录入部门=TT.录入部门
and TT.录入时间 between to_date('2015-05-27 08:00:00','yyyy-mm-dd hh24:mi:ss')
and to_date('2016-05-27 14:30:00','yyyy-mm-dd hh24:mi:ss')
and TT.操作公司='HQA'
and rownum = 1
) ,
TT_3 as(
select D.运单编号 from TT left join 巴枪记录表 D on D.运单编号= TT.运单编号
where 扫描类型 in ('滞留件')
and D.扫描时间 between to_date('2015-05-27 08:00:00','yyyy-mm-dd hh24:mi:ss')
and to_date('2016-05-27 14:30:00','yyyy-mm-dd hh24:mi:ss')
and TT.操作公司='HQA'
and rownum = 1
)
select t.运单编号,t.发件地,t.目的地公司,t.操作公司,t2.录入部门,t.录入时间,t.交接 from TT t left join TT_2 t2 on t.运单编号=t2.运单编号
left join TT_3 t3 on t.运单编号=t3.运单编号
where t.操作公司='SHA' and (t2.运单编号 is not null or t2.运单编号 != '')

转载于:https://www.cnblogs.com/dashanruolong/p/5625753.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值