目的 :查询会议出入记录表(MeetingAccessRecord)的第一次参会时间,会议id,用户id
ps:一个用户有n条出入记录
select * from
(select
join_room_time,MeetingID,user_id,ROW_NUMBER() over(partition by MeetingID,user_id order by join_room_time desc) ma
from MeetingAccessRecord where IsDeleted=0)
as hh
where hh.ma=1
partition by 分组 可以理解为 distinct 后面加的条件
partition by MeetingID,user_id==》distinct MeetingID,user_id
删除重复数据
--删除医院表中重复的数据(根据医院编码和医院名称Code&&Name)保留一条数据
delete from Hospital where ID not in
(select ID from
(select
id, ROW_NUMBER() over(partition by Code,Name order by id desc) ma
from Hospital where IsDeleted=0)
as hh
where hh.ma=1)