impala实现oracle Minus函数

去整理别人的存储过程实现sql的时候,发现用到了oracle的Minus函数,然后就根据业务逻辑实现。sql代码如下:

– 找出在A表中的数据在B表中不存在的数据
SELECT
s.pro_no,
nvl ( s.lsg_month, ‘209912’ ) lsg_month,
s.brd_season_no
FROM
dws_hive.tb1 s
LEFT OUTER JOIN
(
SELECT
s1.pro_no,
s1.lsg_month,
s1.brd_season_no
FROM
( SELECT pro_no, lsg_month, brd_season_no, rank ( ) over ( PARTITION BY pro_no ORDER BY update_sdate DESC ) order_flag FROM dws_hive.tb2 ) s1
WHERE
s1.order_flag = 1
) ss1
ON s.pro_no = ss1.pro_no
WHERE
ss1.pro_no IS NULL

UNION -- 拿出并集

---- 找出在A表和B表都存在但内容不同的数据

SELECT
t.pro_no,
t.lsg_month,
t.brd_season_no
FROM
(
SELECT
IF
(
regexp_replace ( concat( a.lsg_month, a.brd_season_no ), " ", “” ) = regexp_replace ( concat( b.lsg_month, b.brd_season_no ), " ", “” ),
‘’,
a.pro_no
) AS v,
a.pro_no,
a.lsg_month,
a.brd_season_no
FROM
( SELECT s.pro_no, nvl ( s.lsg_month, ‘209912’ ) AS lsg_month, s.brd_season_no FROM dws_hive.tb1 s ) a
JOIN
(
SELECT
pro_no,
lsg_month,
brd_season_no
FROM
( SELECT pro_no, lsg_month, brd_season_no, rank ( ) over ( PARTITION BY pro_no ORDER BY update_sdate DESC ) order_flag FROM dws_hive.tb2 ) s
WHERE
s.order_flag = 1
) b
ON ( a.pro_no = b.pro_no )
) t
WHERE
t.v != ‘’

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值