我在mysql中有这个数据集,对于特定的subject
我希望它们折叠成一行。要回绕的行数各不相同。典型的数据集如下所示:
列名:
Sitting Date | Subject | Exam Part 1 | Exam Part 2 | Assignment Part 1 | Assignment Part 2 | Practical Part 1 | Practical Part 2 | Project Part 1 | Project Part 2 | Overall Mark | Result | Credits
结果:
052012 Business Information Systems 0.00 0.00 51.0 0.00 0.00 0.00 0.00 0.00 42 F 10.00
052012 Business Information Systems 29.0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 42 F 10.00
我想要做的就是将它们包装成一行,如:
052012 | Business Information Systems | 29.00 | 0.00 | 51.0 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 42 | F
我如何在mysql中形成这样的查询?我当前的查询如下所示:
SELECT * FROM exam_results WHERE sdate = :sdate AND studno = :studno
答案 0 :(得分:1)
您可以在MySQL中使用CONCAT_WS
:
SELECT CONCAT_WS(' | ', `Sitting Date`, `Subject`, <...>) FROM `table`