开发者

How to concatenate multiple rows, where fieldnames are duplicated?

I am using SQL.

Here is an example of my table: (There are actually thousands of rows like these, with varying course numbers.)

Course No | Meeting Day | Course Name | Instructor
123       |      M      |    English  |    Smith
123       |      W      |    English  |    Smith
123       |      F      |    Eng开发者_运维技巧lish  |    Smith

I need to concatenate these rows into one like:

123 | MWF | English | Smith

Is this possible? :)

TIA.


In MySQL, you can use the GROUP_CONCAT function with a GROUP BY:

SELECT
  course_no,
  GROUP_CONCAT(DISTINCT meeting_day SEPARATOR '') days,
  course_name,
  instructor
FROM
  courses
GROUP BY
  course_no, course_name, instructor
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜