You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何筛选miembro_documento重复且关联证书日期相同的有效记录

优化后的SQL查询方案

目标查询语句

SELECT 
    pm.miembro_documento,
    p.postulante_postulacion_fecha,
    COUNT(DISTINCT pm.miembro_postulante) AS 重复计数
FROM 
    PostulantesMiembros pm
JOIN 
    Postulantes p ON pm.miembro_postulante = p.postulante_id
GROUP BY 
    pm.miembro_documento,
    p.postulante_postulacion_fecha
HAVING 
    COUNT(DISTINCT pm.miembro_postulante) > 1;

关键优化点说明

  • 用COUNT(DISTINCT pm.miembro_postulante)替代普通COUNT:确保只统计不同证书ID的数量,直接排除同一证书ID下重复出现相同证件号的无效记录
  • 分组维度同时包含miembro_documento和postulante_postulacion_fecha:精准筛选出「同一证件号+同一证书分配日期」下对应多个不同证书ID的场景
  • 通过JOIN关联两张表,一次性获取证件号、证书日期及关联证书ID的关联关系,避免多次子查询带来的性能损耗

内容的提问来源于stack exchange,提问作者BugsOverflow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 17:57:23