我试图获得每个用户组织的最小时间戳,然后是特定操作的日期。感谢您的任何帮助。
我研究了下面的代码,但不确定。
SELECT a1.*
FROM accesscards a1
JOIN (SELECT name, MIN(entrydates) mindate
FROM accesscards
WHERE name != ''
GROUP BY name, date(entrydates)) a2
ON a1.name = a2.name AND a1.entrydates = a2.mindate
当前表
+----------+------+--------+---------------------+
| idRecord | user | action | recorded |
+----------+------+--------+---------------------+
| 1 | bob | start | 2018-01-27 01:00:01 |
+----------+------+--------+---------------------+
| 2 | amy | close | 2018-01-27 01:00:01 |
+----------+------+--------+---------------------+
| 3 | bob | start | 2018-01-27 02:00:01 |
+----------+------+--------+---------------------+
| 4 | amy | start | 2018-01-27 00:00:01 |
+----------+------+--------+---------------------+
| 5 | amy | start | 2018-01-28 00:00:01 |
+----------+------+--------+---------------------+
| 6 | jim | open | 2018-01-28 00:00:01 |
+----------+------+--------+---------------------+
| 7 | bob | close | 2018-01-27 02:00:01 |
+----------+------+--------+---------------------+
| 8 | bob | start | 2018-01-28 00:00:01 |
+----------+------+--------+---------------------+
| 9 | jim | close | 2018-01-28 00:00:01 |
+----------+------+--------+---------------------+
期望的结果
+------+----------+--------+---------------------+
| User | Date | action | recorded |
+------+----------+--------+---------------------+
| amy | 01-27-18 | start | 2018-01-27 00:00:01 |
+------+----------+--------+---------------------+
| amy | 01-28-18 | start | 2018-01-28 00:00:01 |
+------+----------+--------+---------------------+
| bob | 01-27-18 | start | 2018-01-28 01:00:01 |
+------+----------+--------+---------------------+
| bob | 01-28-18 | start | 2018-01-28 00:00:01 |
+------+----------+--------+---------------------+
| jim | 01-28-18 | start | 2018-01-28 00:00:01 |
+------+----------+--------+---------------------+