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
                )
相关推荐
合方圆~小文几秒前
高性能20倍变焦球机转动功能监控设备
数据结构·数据库·数码相机·模块测试
q***58191 小时前
【SQL】MySQL中的字符串处理函数:concat 函数拼接字符串,COALESCE函数处理NULL字符串
数据库·sql·mysql
懒羊羊不懒@1 小时前
【MySQL | 基础】多表查询
数据库·sql·mysql
百***6971 小时前
redis 使用
数据库·redis·缓存
mit6.8241 小时前
[Column] 构建十亿/s级DB | 索引DB&RTDB | Kafka 为中心 | Rust 构建引擎
数据库
q***0561 小时前
在Mysql环境下对数据进行增删改查
数据库·mysql
爬山算法2 小时前
Redis(124)Redis在电商系统中的应用有哪些?
数据库·redis·缓存
武子康2 小时前
Java-170 Neo4j 事务、索引与约束实战:语法、并发陷阱与速修清单
java·开发语言·数据库·sql·nosql·neo4j·索引
数据库学啊3 小时前
靠谱的时序数据库哪家技术强
数据库·时序数据库
Wang's Blog3 小时前
MySQL: 存储引擎深度解析:CSV与Archive的特性、应用与实战演示
数据库·mysql