1

私はMySQLを使用しています。

クエリで常に 5 列の 1 行を返すことができるようにしたいと考えています。次のように、学生テーブルと委員会テーブルがあります。

学生情報テーブル

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

これを簡単に行う方法はありますか?????

4

1 に答える 1

0

次のような委員会テーブルを作成してみてはどうでしょうか。

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

教授の数は静的であるため。

于 2012-04-23T03:12:47.833 に答える