gpt4 book ai didi

SQL:如何从重复行中选择第一条记录?

转载 作者:行者123 更新时间:2023-12-05 00:48:37 25 4
gpt4 key购买 nike

在执行以下查询以查找重复项时

select * from (
select a.* ,count (*) over (partition by a.ID) as tot
from HREMP a
) tt
where tt.tot >1

它返回 423 行,

我执行了另一个查询来查找不重复的记录

  select * from (
select a.* ,count (*) over (partition by a.ID) as tot
from HREMP a
) tt
where tt.tot =1

返回 685 条记录

I found that there are 196 distinct records among the 423 duplicateNow, How to select the first record from duplicate records?

最佳答案

select distinct * 
from ( select a.*, count(*) over (partition by a.ID) as tot
from HREMP a
) tt
where tt.tot > 1

select * 
from ( select a.*
, count(*) over (partition by a.ID) as tot
, row_number() over (partition by a.ID order by 1) as rn
from HREMP a
) tt
where tt.tot > 1
and tt.rn = 1

关于SQL:如何从重复行中选择第一条记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49474997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com