22,206
社区成员
发帖
与我相关
我的任务
分享
--方法一
select * from [table] t
where not exists
(select 1 from [table] where 证件号码 = t.证件号码 and
(逾期期数>t.逾期期数 or (逾期期数 = t.逾期期数 and 逾期金额 > t.逾期金额)))
--方法二
with cte as
(select id=row_number()over(partition by 证件号码 order by 逾期期数 desc,逾期金额 desc),* from [table])
select 证件号码,逾期期数,逾期金额
from cte where id=1
select t.* from tb t where not exists(select 1 from tb where 证件号码 = t.证件号码 and (逾期期数>t.逾期期数
union all
select t.* from tb t where not exists(select 1 from tb where
逾期期数 = t.逾期期数 and 逾期金额 > t.逾期金额)
select * from [table] t
where not exists
(select 1 from tb where 证件号码 = t.证件号码 and
(逾期期数>t.逾期期数 or (逾期期数 = t.逾期期数 and 逾期金额 > t.逾期金额)))
select t.* from tb t where not exists(select 1 from tb where 证件号码 = t.证件号码 and (逾期期数>t.逾期期数 or (逾期期数 = t.逾期期数 and 逾期金额 > t.逾期金额)))