CREATE TABLE test_delete( name varchar(10), value INT ); go -- 张三100 与 王五80 是有重复的 INSERT INTO test_delete SELECT '张三', 100 UNION ALL SELECT '张三', 100 UNION ALL SELECT '李四', 80 UNION ALL SELECT '王五', 80 UNION ALL SELECT '王五', 80 UNION ALL SELECT '赵六', 90 UNION ALL SELECT '赵六', 70 go -- 测试检索数据 SELECT ROW_NUMBER() OVER (PARTITION BY name, value ORDER BY (SELECT 1) ) AS no, name, value FROM test_delete
CREATE VIEW tmp_view AS SELECT ROW_NUMBER() OVER (PARTITION BY name, value ORDER BY (SELECT 1) ) AS no, name, value FROM test_delete
--查重 SELECT ear_id,ctm_code,rvi_code,count(1) FROM [his_hefei].[dbo].[zsb_rvinfo_2022] group by ear_id,ctm_code,rvi_code HAVING COUNT(1) > 1 --创建临时视图 CREATE VIEW tmp_view AS select ROW_NUMBER() OVER (PARTITION BY ear_id, ctm_code, rvi_code ORDER BY (SELECT 1) ) AS num, ear_id, ctm_code, rvi_code from [his_hefei].[dbo].[zsb_rvinfo_2022] --删除重复数据 DELETE FROM tmp_view WHERE num != 1 --释放视图 DROP VIEW tmp_view --检查执行结果 select * from [his_hefei].[dbo].[zsb_rvinfo_2022] where ear_id='000' and ctm_code='000C00000724' and rvi_code='000AD28163606' --剩余数据 select COUNT(1) rvinfo from [his_hefei].[dbo].[zsb_rvinfo] select COUNT(1) rvinfo_2018 from [his_hefei].[dbo].[zsb_rvinfo_2018] select COUNT(1) rvinfo_2019 from [his_hefei].[dbo].[zsb_rvinfo_2019] select COUNT(1) rvinfo_2020 from [his_hefei].[dbo].[zsb_rvinfo_2020] select COUNT(1) rvinfo_2021 from [his_hefei].[dbo].[zsb_rvinfo_2021] select COUNT(1) rvinfo_2022 from [his_hefei].[dbo].[zsb_rvinfo_2022] select COUNT(1) rvinfo_view from [his_hefei].[dbo].[zsb_rvinfo_view]
标签:语句,rvinfo,code,dbo,his,一条,zsb,SQL,SELECT From: https://www.cnblogs.com/mapstar/p/17147201.html