SQL 多变关联使用子查询去重

不去重状态

复制代码
select a.*,
       b.recon_amt
from free_settlement_first a
         left join free_settlement_second b on a.settlement_first_id = b.settlement_first_id

有2条数据出现了重复

使用子查询去重

复制代码
select a.*,
       b.recon_amt
from free_settlement_first a
         left join free_settlement_second b on a.settlement_first_id = b.settlement_first_id
where not exists(select 1
                 from free_settlement_second b2
                 where a.settlement_first_id = b2.settlement_first_id
                   and b.settlement_second_id > b2.settlement_second_id
                )
相关推荐
indexsunny1 小时前
互联网大厂Java求职面试实战:微服务与Spring生态全攻略
java·数据库·spring boot·安全·微服务·面试·消息队列
沪漂阿龙1 小时前
别再让数据库“吃”脏数据了!一文讲透MySQL约束,从入门到精通
数据库·mysql
skiy2 小时前
java与mysql连接 使用mysql-connector-java连接msql
java·开发语言·mysql
2401_873544923 小时前
使用Python进行PDF文件的处理与操作
jvm·数据库·python
虾..3 小时前
多路复用 --- select系统调用
服务器·数据库·sql
杨云龙UP3 小时前
mysqldump逻辑备份文件恢复总结:全库恢复、单库恢复,一篇讲明白
linux·运维·服务器·数据库·mysql·adb
ybwycx3 小时前
mysql重置root密码(适用于5.7和8.0)
数据库·mysql·adb
色空大师4 小时前
【网站搭建实操(一)环境部署】
java·linux·数据库·mysql·网站搭建
亚历克斯神5 小时前
Flutter for OpenHarmony: Flutter 三方库 mutex 为鸿蒙异步任务提供可靠的临界资源互斥锁(并发安全基石)
android·数据库·安全·flutter·华为·harmonyos
IAUTOMOBILE5 小时前
用Python批量处理Excel和CSV文件
jvm·数据库·python