oracle sql 转换成 hive sql -三重子查询union all+运算符改为关联查询中嵌套子查询-子查询转关联查询(十一)

其他sql格式也在更新中,可直接查看这个系列,要是没有你需要的格式,可在评论或私信我

oracle 原sql

select 
	(select nvl(sum(f.money), 0)
	     from F f
	      where f.moneytype = 'GL'
	        and f.busytype in ('YT', 'XT', 'PG', 'PV', 'PD')
	        and f.contno = a.contno
	        and f.insuaccno = a.insuaccno
	        and f.polno = a.polno
	        and f.feecode in (select p.feecode
	                            from lmriskfee p
	                           where p.insuaccno = f.insuaccno
	                             and p.feekind = '03'
	                             and p.feetakeplace in ('09', '10')
	                          union all
	                          select '000000' from dual)) +
	    (select nvl(abs(sum(lc.fee)), 0)
	       from LC lc
	      where lc.contno = a.contno
	        and lc.insuaccno = a.insuaccno
	        and lc.polno = a.polno
	        and lc.feecode in
	            (select p.feecode
	               from P p
	              where p.feekind = '03'
	                and p.feeitemtype = '01'
	                and p.feetakeplace = '01')) as Acc,
from 
	A a

hive 改sql

select 
  nvl(b.money,
       0)+ nvl(c.fee,
       0)
from 
	A a
	left join (
        select
                nvl(sum(f.money),
                0) as money,
                f.contno,
                f.insuaccno,
                f.polno
        from
                F f
        where
                f.moneytype = 'GL'
                and f.busytype in ('YT', 'XT', 'PG', 'PV', 'PD')
                and f.feecode in (
                select
                        p.feecode
                from
                       P p
                inner join F f on
                        p.insuaccno = f.insuaccno
                where
                        p.feekind = '03'
                        and p.feetakeplace in ('09', '10')
        union all
                select
                        '000000')
        group by
                f.contno,
                f.insuaccno,
                f.polno) b on
        b.contno = a.contno
        and b.insuaccno = a.insuaccno
        and b.polno = a.polno
left join (
        select
                nvl(sum(f.fee),
                0) as fee,
                f.contno,
                f.insuaccno,
                f.polno
        from
                F f
        where
                f.feecode in (
                select
                        p.feecode
                from
                        P p
                where
                        p.feekind = '03'
                        and p.feetakeplace = '01'
                        and p.feetakeplace = '01'
        union all
                select
                        '000000')
        group by
                f.contno,
                f.insuaccno,
                f.polno) c on
        c.contno = a.contno
        and c.insuaccno = a.insuaccno
        and c.polno = a.polno
	

注:可当练习(~。 ~)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值