gpt4 book ai didi

mysql - 如何选择仅一个字段和所有其他字段值重复的记录?

转载 作者:行者123 更新时间:2023-11-29 10:50:35 25 4
gpt4 key购买 nike

我有表名称= 时间表

 --------------------------------------------
| course_id | room | day | time |
--------------------------------------------
| 2 | 401 |saturday| 9:00 - 13:00 |
--------------------------------------------
| 3 | 401 | sunday | 9:00 - 13:00 |
--------------------------------------------
| 2 | 402 | monday | 9:00 - 13:00 |
--------------------------------------------
| 3 | 403 | tuesday| 14:00 - 17:00|
--------------------------------------------
| 4 | 401 | tuesday| 9:00 - 13:00 |
--------------------------------------------
| 2 | 402 |wednesday|14:00 - 17:00|
--------------------------------------------

另一个表名称=类(class)

----------------------------------
| id | course_code | course_name |
----------------------------------
| 2 | cse | cse |
------------------------
| 3 | eee | eee |
----------------------
| 4 | ct | ct |
-----------------------

现在如何获得这样的输出..

----------------------------------
| course code | course name | info |
----------------------------------
|cse | cse |401,satueday-9:00-13:00; 402,monday-9:00-13:00; 402,wednesday-14:00-17:00|
------------------------
| eee | eee | 401,sunday-9:00-13:00;403,tuesday-14:00-17:00 |
------------------------
| ct | ct | 401,tuesday-9:00-13:00|
-----------------------

最佳答案

您可以使用group_concat

select c.course_code,
c.course_name,
group_concat(concat(s.room, ',', s.day, '-', s.time) separator ';')
from course c
join schedule s on s.course_id = c.id
group by c.course_code,
c.course_name;

关于mysql - 如何选择仅一个字段和所有其他字段值重复的记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43812279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com