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
                )
相关推荐
TDengine (老段)1 小时前
TDengine 常见问题 TOP3
大数据·数据库·物联网·时序数据库·tdengine·涛思数据
Lucifer三思而后行3 小时前
Oracle SQL 优化实战:明明走了索引,SQL 还是慢?
sql·oracle
螺蛳粉 螺蛳粉4 小时前
MySQL 分布式集群系列 · 第五篇——全方位对比:NDB、MGR、主从复制、分库分表怎么选?
数据库·分布式·mysql
泡泡鱼(敲代码中)5 小时前
MySQL 学习笔记:DCL、函数与约束 —— 安全、效率、完整性的三板斧
开发语言·笔记·sql·学习·mysql·gitee
这个DBA有点耶8 小时前
从OLTP到OLAP到HTAP:数据库负载分类的技术演进与选型指南
数据库·mysql·架构
润乾软件8 小时前
SQLazy: 在分组内搜索指定偏移量的相邻记录
sql·sqlazy
YangYang9YangYan9 小时前
商业数据分析校招项目怎么选,附项目设计与简历包装思路
大数据·数据库·数据分析
李白客9 小时前
数据库培训怎么选?零基础到DBA的学习路线与机构认证对比(2026)
数据库·学习
shark-chili10 小时前
关于AI辅助编程的认知
数据库·人工智能·redis·macos·缓存
SendTomo10 小时前
.ico透明图标在线生成下载平台深度解析
大数据·数据结构·数据库·数据仓库·个人开发