34,587
社区成员
发帖
与我相关
我的任务
分享
补充一个,屡试不爽
select * from (
select * ,rn = row_number() over (partition by 终端号 order by 记录时间 desc)from tb
)t where rn = 1
select t.* from tableA t where not exists(select 1 from tableA where 终端号=t.终端号 and 记录时间>t.记录时间)
那就这样,这样比较直接
select termNum 终端号,max(readTime) 记录时间,CardNo 卡号
from tableA
group by termNum ,CardNo
select t.* from tableA t where not exists(select 1 from tableA where 终端号=t.终端号 and 记录时间>t.记录时间)
select t.* from tableA t where t.记录时间=(select top 1 记录时间 from tableA where 终端号=t.终端号 order by 记录时间 desc)
select t.* from tableA t where t.记录时间=(select max(记录时间) from tableA where 终端号=t.终端号)
select a.* from tableA a,(select 终端号,max(记录时间) as 记录时间 from tableA group by 终端号) b where a.终端号=b.终端号 and a.记录时间=b.记录时间
SELECT 卡号,最近刷卡时间=MAX(记录时间) FROM TB GROUP BY 卡号
select t.* from tableA t where not exists(select 1 from tableA where 终端号=t.终端号 and 记录时间>t.记录时间)