Get groups of object ids with datetime grouped by date

↘锁芯ラ 提交于 2021-01-29 07:42:00

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!