sql server 语句 查询数据库某个字段的最后一条数据

2024-12-13 06:04:49
推荐回答(4个)
回答1:

select 工号、卡号、消费时间 from A
where 消费时间 in (select max(消费时间) FROM A group by 工号)

得到每个工号最后一条消费记录

回答2:

select * from a where exists (select 1 from (select 工号,max(消费时间) as 消费时间 group by 工号) as b where a.工号=b.工号 and a.消费时间=b.消费时间)

回答3:

select top 1 * from 消费明细表 where 工号=工号 order by 消费时间 desc

回答4:

select gonghao,kahao,max(xiaofeishijian) from A group by gonghao order by kahao