我有一个包含DATETIME字段的记录表。我想根据时间分割(早上6点)选择具有组号的记录。
例如:星期一早上6:00之前的所有记录都有一个group_id为1.之后的任何值,直到星期二早上6:00,group_id为2,星期三早上6:00之后group_id为3,依此类推。
记录示例:
========================================
|ID |timestamp |value |
========================================
|0 |2012-03-00 18:20:00 |John |
|1 |2012-03-01 02:44:00 |Sally |
|2 |2012-03-01 03:12:00 |Mike |
|3 |2012-03-01 08:51:00 |Art |
|4 |2012-03-02 01:20:00 |Kate |
|5 |2012-03-03 01:20:00 |Susan |
|6 |2012-03-05 07:46:00 |Sam |
========================================
目标:
===================================================
|ID |timestamp |value |group_id |
===================================================
|0 |2012-03-00 18:20:00 |John |1 |
|1 |2012-03-01 02:44:00 |Sally |1 |
|2 |2012-03-01 03:12:00 |Mike |1 |
|3 |2012-03-01 08:51:00 |Art |2 |
|4 |2012-03-02 01:20:00 |Kate |2 |
|5 |2012-03-03 01:20:00 |Susan |3 |
|6 |2012-03-05 07:46:00 |Sam |4 |
===================================================
任何想法?