如何查询 SQL 表并从结果集中删除重复行 [英] How to query SQL Table and remove duplicate rows from a result set
本文介绍了如何查询 SQL 表并从结果集中删除重复行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道这很简单...
请告诉我如何获得第 1、9、18 和 21 行的结果集(基于所附图像)??
Please advise on how I can get a result set of rows 1, 9, 18, and 21 (based on the attached image)??
谢谢,
布拉德
推荐答案
如果每一列的行确实不同,那么您可以使用 SELECT DISTINCT
.
If the rows are truly distinct across every column, then you can use SELECT DISTINCT
.
由于您使用的是 SQL Server,您还可以使用 row_number()
为每个 ThreatId
返回一行:
Since you are using SQL Server you can also use row_number()
to return one row for each ThreatId
:
select ThreatId,
ThreatTopClient,
...
from
(
select ThreatId,
ThreatTopClient,
...,
row_number() over(partition by ThreatId order by ThreatMLSeq) rn
from xThreatCA
where ThreatMLSeq <> N''
and ID <> 0
) d
where rn = 1
order by ThreatMLSeq
这篇关于如何查询 SQL 表并从结果集中删除重复行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文