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
                )
相关推荐
智购科技智能售货柜27 分钟前
2026自动售货机整机可靠性测试:从高低温交变到EMC电磁兼容的认证工程实践~YH
运维·服务器·数据库·人工智能·物联网
ltl42 分钟前
RocksDB 架构演进:相对 LevelDB 的 diff 地图
数据库
ltl43 分钟前
存储读取性能优化:索引、Bloom Filter 与读放大
数据库
xier_ran4 小时前
【infra之路】GPU 存储层次总结:L1 / L2 / HBM
java·网络·数据库
山甫aa6 小时前
Javaweb---MyBatis增删改查
java·数据库·后端·mybatis·springboot
其实防守也摸鱼6 小时前
接口审计:从原理到实践的万字深度指南
数据库·安全·自动化·github·copilot
@insist1237 小时前
系统集成项目管理工程师-信息和文档管理
网络·数据库·软考·系统集成项目管理工程师·软考中项·软件水平考试
残 风8 小时前
PostgreSQL 存储机制详解
数据库·postgresql·开源·数据库开发
JacksonMx9 小时前
Java CompletableFuture 异步编程实战:从入门到架构师避坑指南
linux·数据库·python