gpt4 book ai didi

mysql - 使用 group_concat 如何将每个值迭代为一列

转载 作者:行者123 更新时间:2023-11-30 23:31:41 25 4
gpt4 key购买 nike

我正在使用 MySQL。

我希望能够在我的查询中始终返回 1 行和 5 列。我有一张学生表和一张委员会表,如下所示:

学生信息表

Student_Number    Committee_Id
00000001 5

委员会表

Committee Id         Prof_Id
5 23
5 55
5 6
5 10

使用这个语句:

select committee_id, group_concat(prof_id) as profs from committee_table 

我得到:

profs        committee_id
23,55,6,10 5

我要返回:

prof1 prof2 prof3 prof4 prof5
23 55 6 10 null

有什么简单的办法吗?????

最佳答案

你试试这样创建你的委员会表:

create table committee(committee_id datatype,prof1 datatype,prof2 datatype,prof3 datatype,prof4 datatype,prof5 datatype); 

因为教授的数量是静态的。

关于mysql - 使用 group_concat 如何将每个值迭代为一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10274334/

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