欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

sqlsever 查询最后一条数据

程序员文章站 2022-06-05 08:07:09
select * from(select row_number() over(partition by IDCARD order by DATATM desc) as rownum,* from (SELECT * FROM TABLENAME)as H1 ) as H where H.rownum ......

select * from(select row_number()
over(partition by IDCARD order by DATATM desc) as rownum,*
from (SELECT
*
FROM
TABLENAME
)as H1
) as H where H.rownum =
1

解释:红色为以什么分组   蓝色为以什么排序  紫色为表名   目前是获取表中每个 IDCARD中时间最大的一条