@犀牛
--变化数据
SELECT
cod_cust_id
,amt_credit_new
,dat_create
FROM (
SELECT
cod_cust_id
,amt_credit_new
,dat_create
,ROW_NUMBER()
OVER (PARTITION BY cod_cust_id,SUBSTRING(dat_create,1,10) ORDER BY dat_create DESC ) AS rn--如果客户在同一天多次申请通过,则取日期最大那次
FROM thai_dw.snap_cmisdb_cmis_card_limit_change
WHERE flg_status_apply =8
)
WHERE rn =1
;
--没有发生变化的数据
SELECT
p2.cod_cust_id
,p2.amt_credit
,p2.dat_create
FROM (
SELECT
cod_cust_id
,amt_credit_new
FROM (
SELECT
cod_cust_id
,amt_credit_new
,dat_create
,ROW_NUMBER()
OVER (PARTITION BY cod_cust_id,SUBSTRING(dat_create,1,10) ORDER BY dat_create DESC ) AS rn--如果客户在同一天多次申请通过,则取日期最大那次
FROM thai_dw.snap_cmisdb_cmis_card_limit_change
WHERE flg_status_apply =8
)
WHERE rn =1
) p1
RIGHT JOIN (
SELECT
cod_cust_id
,amt_credit
,dat_create
FROM thai_dw.snap_cmisdb_cmis_card_apply
WHERE flg_status_apply =8
) p2
ON p1.cod_cust_id = p2.cod_cust_id
WHERE p1.cod_cust_id IS NULL
;
我以数据创建时间dat_create作为starttime,什么为endtime呢?没有发生变化的数据mark都是i,发生变化的数据mark都是u可以吗?因为不会有数据被删除