查询考勤时间:每天分钟和最长时间

时间:2011-09-30 04:05:48

标签: mysql sql

有人可以帮助我 我在mysql中有eventime字段类型datetime 恩。平时记录:

2011-09-01 10:29:37
2011-09-01 10:50:04
2011-09-01 17:10:45
2011-09-02 08:30:01
2011-09-02 .....
2011-09-02 .....
2011-09-03 .....
2011-09-03 .....
2011-09-03 .....
.....
2011-09-30 08:15:10
2011-09-30 11:40:44
2011-09-30 15:50:40
2011-09-30 17:50:11

我希望按日查询结果首次登录和最后一次登录组 例如:

   Day     |   first login  |  last login
-----------+----------------+-------------
2011-09-01 |     10:29:37   |    17:10:45
2011-09-02 |     08:30:01   |    17:15:00
2011-09-03 |     07:10:45   |    17:10:12
2011-09-14 |     07:50:25   |    16:12:45
.......
2011-09-30 |     08:15:10   |    17:50:11

可以帮我查一下mysql group中按日期或者偶数查询的代码吗? 感谢

3 个答案:

答案 0 :(得分:2)

这应该可以解决问题:

SELECT
    MIN(login_time) AS `first login`,
    MAX(login_time) AS `last login`
FROM
    login_table
GROUP BY
    DATE(login_time)

答案 1 :(得分:0)

select min(eventtime) AS min_event_time, max(eventtime) AS max_event_time FROM table;

答案 2 :(得分:-1)

与此类似的东西

select min(eventtime) as sTime, max(eventtime) as eTime
from yourtable
group by [someuseridorsomethingcolumn]
where [useridcolumn] = 'anActualUserID'