sql-server - 停用基于两个分组列的重复数据,检查不为空
问题描述
我有以下查询以 2 列返回重复行,但它返回具有 NULL 值的行。我想为两列返回 NOT NULL 的行。另外,如何停用旧 ID 的重复记录?
With deactivaterows as (
Select t.*, count(*) over (partition by col1, col2) as cnt from TABLE1 t)
Select * from deactivaterows where cnt > 1;
解决方案
您希望 row_number 不计数(*):
with deactivaterows as
(
select t.*, row_number() over(partition by t.col1, t.col2 order by (select null)) as rn
from TABLE1
where t.col1 is not null and t.col2 is not null
)
select * from deactivaterows where rn > 1
推荐阅读
- r - R:过渡检测的自动化
- docker - Kubernetes 1.17.2 Rancher 2.3.5 CreateContainerConfigError: stat no such file or directory but the directory is there
- python - python smtplib不发送带有office365地址的电子邮件
- javascript - xModal 窗口只打开一次,比我需要刷新页面
- python - 如何将文本文件中的数据导入熊猫数据框
- android - 如何在 WebView 中禁用复制但启用粘贴?
- javascript - HTML/JS:在元素之间画任意线?
- assembly - MASM 二进制密码匹配检查
- javascript - 使 `npm ls somepackage` 命令尊重版本范围
- r - 转换数据框中的列表折叠一列并在 R 中保持其他列不变