select * from
(
--获取冗余数据中的唯一最小行数据
select * from table_1 t1
where t1.id in
(
select min(t2.id) from table_1 t2
group by t2.employeeid having t1.employeeid=t2.employeeid and count(*) > 1
)
union all
--获取非冗余数据
select * from table_1 t4 where t4.id in
(
select min(t3.id) from table_1 t3
group by t3.employeeid having t4.employeeid = t3.employeeid and count(*) = 1
)
) t5 order by id
(
--获取冗余数据中的唯一最小行数据
select * from table_1 t1
where t1.id in
(
select min(t2.id) from table_1 t2
group by t2.employeeid having t1.employeeid=t2.employeeid and count(*) > 1
)
union all
--获取非冗余数据
select * from table_1 t4 where t4.id in
(
select min(t3.id) from table_1 t3
group by t3.employeeid having t4.employeeid = t3.employeeid and count(*) = 1
)
) t5 order by id
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步