xinli/检查重复信息编号.sql
2025-12-02 15:12:55 +08:00

43 lines
1.3 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 检查重复的信息编号 SQL 脚本
-- 用于排查用户导入时"信息编号已存在"的问题
-- 1. 检查这些信息编号在数据库中是否真的存在
SELECT
info_number AS ,
user_name AS ,
create_time AS ,
create_by AS
FROM psy_user_profile
WHERE info_number IN ('34', '99', '114', '120', '121', '122', '123', '124')
ORDER BY info_number;
-- 2. 检查数据库中所有重复的信息编号
SELECT
info_number AS ,
COUNT(*) AS ,
GROUP_CONCAT(user_name) AS ,
GROUP_CONCAT(profile_id) AS ID列表
FROM psy_user_profile
WHERE info_number IS NOT NULL AND info_number != ''
GROUP BY info_number
HAVING COUNT(*) > 1
ORDER BY COUNT(*) DESC;
-- 3. 查看最近导入的用户最近100条
SELECT
info_number AS ,
user_name AS ,
create_time AS ,
create_by AS
FROM psy_user_profile
ORDER BY create_time DESC
LIMIT 100;
-- 4. 统计信息编号的使用情况
SELECT
COUNT(DISTINCT info_number) AS ,
COUNT(*) AS ,
(COUNT(*) - COUNT(DISTINCT info_number)) AS
FROM psy_user_profile
WHERE info_number IS NOT NULL AND info_number != '';