相关文章推荐
select PId from Test t where time = ( select max (time) from Test t1 where t1.PId = t.PId) group by Pid time = ( select max (time) from Test t1 where t1.PId = t.PId) select row_number() over (partition by [ Pid ] order by [ Time ] desc /*降序是为了where KeyId=1 (1是固定值第一条),如果升序由于不知道每组多少条where中KeyId就无法过滤了*/ ) as KeyId, * from Test where KeyId = 1

From: https://www.cnblogs.com/xuejianxiyang/p/11980908.html

DROP TABLE IF EXISTS ##tmpTable;  --存在表则删除

select CONVERT(varchar(100), @time, 23) --取datetime的年月日 2019-12-17

select CONVERT(varchar(100), GETDATE(), 24) --取datetime的时间 10:57:47

 
推荐文章