34,593
社区成员
发帖
与我相关
我的任务
分享
;with f as
(
select a.* from Sheet1$ a inner join
(select huzhbiha,huwubiha from Sheet1$ group by huzhbiha,huwubiha having count(*)>1) b
on a.huzhbiha=b.huzhbiha and a.huwubiha=b.huwubiha
where a.huzhbiha='SUNX01' and a.huwubiha='1314-0002-02'
)
select
*
from
f t
where
id=(select max(id) from f where huzhbiha = t.huzhbiha and huwubiha = t.huwubiha ) --或者日期什么的
select * from
(
select row_number() over (partition by huzhbiha,huwubiha order by huzhbiha) as rowindex,*
(
select a.* from Sheet1$ a inner join
(select huzhbiha,huwubiha from Sheet1$ group by huzhbiha,huwubiha having count(*)>1) b
on a.huzhbiha=b.huzhbiha and a.huwubiha=b.huwubiha
where a.huzhbiha='SUNX01' and a.huwubiha='1314-0002-02'
)t1
)t2
where rowindex = 1
with ct1 as
(
select a.* from Sheet1$ a inner join
(select huzhbiha,huwubiha from Sheet1$ group by huzhbiha,huwubiha having count(*)>1) b
on a.huzhbiha=b.huzhbiha and a.huwubiha=b.huwubiha
where a.huzhbiha='SUNX01' and a.huwubiha='1314-0002-02'
)
select *
from ct1 t
where not exists (select 1 from ct1 where huzhbiha = t.huzhbiha and huwubiha = t.huwubiha and id > t.id) --或者日期什么的