执行sql内层res表查询 结果如下
在res表外加上rn=1后 select 不变 结果如下
相同sql在spark执行 数据字段值不会发生改变
sql如下:
select * from (
SELECT
t.lz_claim_date,
t.zy_claim_date,
t.lz_flag,
t.id,
t.borrow_id,
sum( capital_amount ) over ( PARTITION BY t.borrow_id ) AS capital_amount,
0 AS rate_amount,
round( sum( bb.capital_amount ) over ( PARTITION BY t.borrow_id ) * 10.6 / 36500 * 3, 2 ) AS overdue_amount,
row_number() over ( PARTITION BY t.lz_claim_date, t.zy_claim_date, t.lz_flag, t.id, t.borrow_id order by 1) rn
FROM
(
SELECT
z.lz_claim_date,
z.zy_claim_date,
z.lz_flag,
min( bill_id ) AS id,
borrow_id
FROM
tmp.js_detail_zyxj_dc_bill_p0 z
WHERE
z.lz_flag = 2
GROUP BY
z.lz_claim_date,
z.zy_claim_date,
z.lz_flag,
borrow_id
) t
LEFT JOIN ods.lt_lt_borrow_bill_new bb ON bb.id > t.id
AND bb.borrow_id = t.borrow_id
WHERE
bb.id IS NOT NULL and borrow_id = 2138376
) res
WHERE
res.rn = 1