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
                )
相关推荐
czhaii25 分钟前
STC ai助手单片机工程项目创建实例
数据库·mongodb
山峰哥41 分钟前
数据库性能救星:Explain执行计划深度拆解
服务器·开发语言·数据库·sql·启发式算法
oradh1 小时前
Oracle 11g rac IP地址修改(public ip、vip、scan ip、priviate ip)
数据库·tcp/ip·oracle·rac ip地址修改
YOU OU2 小时前
Redis哨兵 & 集群
数据库·redis·sentinel
小罗水2 小时前
第8章 文档解析与文本切片
数据库·spring·spring cloud·微服务
瞬间&永恒~2 小时前
【MySQL】 主从复制多拓扑搭建实验
运维·数据库·mysql·云原生
han_hanker2 小时前
sql语法 DECODE, CASE ... WHEN
数据库·sql·oracle
井川廊咏3 小时前
vi 删除指定范围的行,不用再反复按 dd
数据库·mysql
小码农 - 初3 小时前
MySQL前言
mysql
z落落3 小时前
StudentInfo表 分页、增删改 存储过程+C# WinForm 存储过程实现分页和增删改查
数据库·sql·mysql