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
                )
相关推荐
JavaBoy_XJ12 小时前
Mysql在 Spring Boot 项目中的完整配置指南
数据库·spring boot·mysql·mysql配置
paopaokaka_luck12 小时前
基于SpringBoot+Vue的高校心理健康服务平台(websocket实时聊天、AI分析、Echarts图形化分析)
vue.js·spring boot·websocket·mysql·echarts
云和数据.ChenGuang12 小时前
openEuler 上安装与部署 Redis 运维教程
运维·数据库·redis·运维工程师·运维技术
元气满满-樱12 小时前
MySql源码安装
数据库·mysql·adb
妮妮喔妮12 小时前
Redis Cluster故障处理机制
java·数据库·redis
Elastic 中国社区官方博客12 小时前
AutoOps 实际应用:调查 ECK 上的 Elasticsearch 集群性能
大数据·数据库·elasticsearch·搜索引擎·全文检索
欧克小奥12 小时前
Redis单节点分片集群实现
数据库·redis·缓存
霑潇雨12 小时前
题解 | 统计每个产品的销售情况
数据库·sql·笔试·牛客
写代码的【黑咖啡】12 小时前
Apache Flink SQL 入门与常见问题解析
sql·flink·apache
不穿格子的程序员12 小时前
Redis篇1——Redis深度剖析:从 5 种对象到 6 大底层结构
数据库·redis·缓存·redis五大数据类型·redis六大数据结构