如何比较sql server中的时间戳

时间:2022-04-03 13:36:31

Given the following table, how can I select the most recent timestamp from a given user?

根据下表,如何从给定用户中选择最新的时间戳?

Here is my table:

这是我的表:

如何比较sql server中的时间戳

For instance, if USERID 5, I want to compare every USERID 5 timestamp and return the most recent timestamp.

例如,如果是USERID 5,我想比较每个USERID 5时间戳并返回最新的时间戳。

2 个解决方案

#1


0  

Not sure if I understand correctly?

不确定我是否理解正确?

Maybe it is just as simple as that?

也许就这么简单?

SELECT MAX(CHECKTIME) FROM Table WHERE UserID = 5

If not, you could google for OVER clause.

如果没有,你可以google for OVER子句。

#2


1  

If you want the latest timestamp for a user you can use the max function:

如果您想为用户提供最新的时间戳,可以使用max函数:

select userid, max(checktime) 
from your_table 
group by userid 
where userid = 5 

If you remove the where clause you'll get a list of all userid with their latest checktime.

如果删除where子句,您将获得所有用户ID及其最新检查时间的列表。

#1


0  

Not sure if I understand correctly?

不确定我是否理解正确?

Maybe it is just as simple as that?

也许就这么简单?

SELECT MAX(CHECKTIME) FROM Table WHERE UserID = 5

If not, you could google for OVER clause.

如果没有,你可以google for OVER子句。

#2


1  

If you want the latest timestamp for a user you can use the max function:

如果您想为用户提供最新的时间戳,可以使用max函数:

select userid, max(checktime) 
from your_table 
group by userid 
where userid = 5 

If you remove the where clause you'll get a list of all userid with their latest checktime.

如果删除where子句,您将获得所有用户ID及其最新检查时间的列表。