有用的SQL

    最近做项目,遇到了几个有用的SQL,拿来大家分享下......

    1 合并:

    select a.bill_id as old_bill_id,a.bill_id,a.business_bill_id,to_char(a.business_date,'YYYY-   MM-DD') as business_date,
     a.org_id,so.org_name,a.operator_id,se.name
 from doa_appl_master a,sys_org so,sys_operator sor,sys_employee se
 where so. org_id = a.org_id
 and a.operator_id=sor.operator_id
 and sor.employee_id = se.employee_id
 and a.business_type_id='27'
 and a.check_mark='1'
 and a.mark='0'
 and a.org_id={ORG_ID}
 union all
 select b.appl_bill_id as old_bill_id,b.bill_id,b.business_bill_id,to_char(b.business_date,'YYYY-MM-DD') as business_date,
     b.org_id,sog.org_name,b.operator_id,see.name
 from doa_master b,sys_org sog,sys_operator sop,sys_employee see
 where b.org_id = sog.org_id
 and b.operator_id=sop.operator_id
 and sop.employee_id = see.employee_id
 and b.business_type_id='30'
 and b.bill_id in (select c.bill_id from doa_detail c where c.mark='3' and c.result='0')
 and b.confirm_mark='1'
 and b.mark='0'
 and b.org_id={ORG_ID}
 order by bill_id Desc

 2 字符截取

  select dom.bill_id,
         dom.business_type_id,
         to_char(dom.business_date, 'YYYY-MM-DD') as business_date,
         dom.appl_bill_id,dom.corres_bill_id,
         dom.operator_id,sog.org_name,se.name
    from doa_master dom,sys_org sog,sys_operator sor,sys_employee se
    where substr(dom.child_org_id,instr(dom.child_org_id,',',-1)+1)=sog.org_id
    and dom.operator_id=sor.operator_id
    and sor.employee_id = se.employee_id
    and dom.business_type_id='28'
    and dom.mark='0'
    and TO_DATE(dom.business_date) <= TO_DATE(sysdate) 
    and TO_DATE(dom.business_date) > TO_DATE(sysdate) - 3
    and dom.parent_org_id={ORG_ID}
    order by bill_id desc

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值