[英]In Access,get the Max time and min time using sql
我的表就是这样,当用户ID为A或B时,我想获取Maxtime和Mintime。
user_id time
---------- ----------
A 2016-01-03 23:02:35
A 2016-01-03 23:02:36
A 2016-01-03 23:02:38
B 2016-01-03 22:02:35
B 2016-01-03 22:02:39
我的代码是:
SELECT user_id,Max(time)AS [start], Min(time) AS [end]
FROM client1
WHERE user_id is not null
GROUP BY user_id
HAVING user_id in (select user_id from client1);
我用access作为数据库,就像这样的搜索
我的猜测是,以下选择应返回期望的结果:
SELECT user_id,Max(time)AS [start], Min(time) AS [end]
FROM client1
WHERE user_id IN ('A', 'B', 'C', 'D', 'Any other value')
GROUP BY user_id
注意:要为所有用户获取最小和最大时间,只需删除WHERE
子句:
SELECT user_id,Max(time)AS [start], Min(time) AS [end] FROM client1
GROUP BY user_id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.