问题
Let's say we have table like this:
+----------------------------------+----------------------------+
| id | start |
+----------------------------------+----------------------------+
| 06c561305383482e98064ssdfd6ccf74 | 2019-08-30 14:41:40.697301 |
| 0aec07d9acdd48c485ab3sfhsffdsa8c | 2019-09-02 05:45:09.274541 |
| 0d240asdfasd49579e2be8821b908fdc | 2019-09-02 05:45:08.745885 |
| 00al4eebb9a34sdsdfsdff128518dc4f | 2019-08-30 14:42:29.094314 |
Is it possible to get data in structure similar to this in single query? I want to get data grouped by unique dates with all object ids in date group.
date:
2019-08-30:
ids:
- 06c561305383482e98064ssdfd6ccf74
- 00al4eebb9a34sdsdfsdff128518dc4f
2019-09-02:
ids:
- 0aec07d9acdd48c485ab3sfhsffdsa8c
- 0d240asdfasd49579e2be8821b908fdc
回答1:
Thanks @Salaman
SELECT DATE(tab.start), GROUP_CONCAT(id) FROM tab GROUP BY DATE(tab.start);
Works like a charm!
Remember also about setting:
SET SESSION group_concat_max_len = @@max_allowed_packet;
来源:https://stackoverflow.com/questions/58009249/get-groups-of-object-ids-with-datetime-grouped-by-date