鉴于此表,
+----+------------------+-----------+----------+
| id | Doctor name | firsttime | lasttime |
+----+------------------+-----------+----------+
| 1 | Dr. Abdurahman | 12:00:00 | 21:00:00 |
| 2 | Dr. Sultan Hamid | 12:00:00 | 21:00:00 |
| 3 | Dr. Susanti | 12:00:00 | 21:00:00 |
| 4 | Dr. Siparman | 12:00:00 | 21:00:00 |
| 5 | Dr. Ramah | 12:00:00 | 21:00:00 |
| 6 | Drs. Susanto | 13:00:00 | 22:00:00 |
| 7 | Dr. Budiarjo | 13:00:00 | 22:00:00 |
| 8 | Dr. Antonius | 13:00:00 | 22:00:00 |
| 9 | Dr. Wahid Bahyu | 13:00:00 | 22:00:00 |
+----+------------------+-----------+----------+
expected
+----+--------------------------------------------+-----------+----------+
| id | Doctor name | firsttime | lasttime |
+----+--------------------------------------------+-----------+----------+
| 1 | Dr. Abdurahman, Dr. Sultan Hamid, etc | 12:00:00 | 21:00:00 |
| 2 | Drs. Susanto, Dr. Budiarjo, etc | 13:00:00 | 22:00:00 |
+----+--------------------------------------------+-----------+----------+
我期待的是根据第一次和最后一次选择基于医生名称的组连续的表格。因此,如果有相同的第一个日期和最后一个日期,它将被包含在组concat中
注意:第一个日期和最后一个日期是随机的,忽略等,我想要它的全名医生
使用GROUP_CONCAT
SELECT firstdate,lastdate,
GROUP_CONCAT(doctorname)
FROM
table group by firstdate,lastdate
或者你可以使用STRING_AGG()函数:
SELECT STRING_AGG(Doctor name, ', ') AS Doctor name,
firsttime,
lasttime
FROM table
GROUP BY firstdate, lastdate;