开发者

Query for time attendance : min and max hours group by day

开发者 https://www.devze.com 2023-04-09 05:42 出处:网络
Somebody can help me. I have eventime field type datetime in mysql ex. eventime record: 2011-09-01 10:29:37

Somebody can help me.

I have eventime field type datetime in mysql

ex. eventime record:

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

I want to query with result first login and last login group by day.

ex:

   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

Can help me how code query in mysql group by date or eventime?

Thanks


This should do the trick:

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


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


something similar to this

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

精彩评论

暂无评论...
验证码 换一张
取 消