基于当前日期时间的值(外部表中的当前日期时间)

时间:2019-08-13 16:22:05

标签: sql-server sql-server-2008-r2

当前,我有要根据最新日期和时间提取的数据。日期时间在外部表中列出,该外部表是通过联接聚集在一起的。

Date_Local                 Name     Value
2019-08-13 10:30:54.377    Ted       20
2019-08-13 10:30:54.377    Jake      50
2019-08-12 09:10:55.377     Ben      30

结果:-

预期结果是提取Ted和Jake数据行。

1 个答案:

答案 0 :(得分:0)

enter image description here

SELECT T.Date_Local,T.Name,T.value
FROM tbladata T
INNER JOIN
(
SELECT ROW_NUMBER() OVER(PARTITION BY Date_Local ORDER BY Date_Local) as rowNum,
       Name,
       Value,
       Date_Local
FROM tblaData
) AS sub ON(T.Date_Local=sub.Date_Local)
WHERE sub.rowNum>1