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
                )

相关推荐

  1. sql LISTAGG

    2024-07-15 01:22:03       22 阅读
  2. SQL查询:如何在where条件中使用查询

    2024-07-15 01:22:03       35 阅读
  3. 使用 MySQL 查询和 CASE 语句判断关联状态

    2024-07-15 01:22:03       32 阅读
  4. My SQL 查询

    2024-07-15 01:22:03       42 阅读
  5. 动态sql关联查询

    2024-07-15 01:22:03       49 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-15 01:22:03       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-15 01:22:03       71 阅读
  3. 在Django里面运行非项目文件

    2024-07-15 01:22:03       58 阅读
  4. Python语言-面向对象

    2024-07-15 01:22:03       69 阅读

热门阅读

  1. apache Kylin系列介绍及配置

    2024-07-15 01:22:03       17 阅读
  2. Hudi 索引总结 - Parquet布隆过滤器写入过程

    2024-07-15 01:22:03       22 阅读
  3. Spring源码(四) Aware 接口

    2024-07-15 01:22:03       22 阅读
  4. 12、如何用事件风暴构建领域模型

    2024-07-15 01:22:03       20 阅读
  5. 免杀中用到的工具

    2024-07-15 01:22:03       18 阅读
  6. 【FPGA】Verilog 中 typedef enum 用法教程

    2024-07-15 01:22:03       17 阅读
  7. React@16.x(58)Redux@4.x(7)- 实现 combineReducers

    2024-07-15 01:22:03       21 阅读
  8. springsecurity01

    2024-07-15 01:22:03       15 阅读
  9. this指向解析

    2024-07-15 01:22:03       21 阅读
  10. AI究竟是在帮助开发者还是取代他们?

    2024-07-15 01:22:03       20 阅读
  11. C语言 判断素数

    2024-07-15 01:22:03       18 阅读