开发者

How to concatenate multiple rows, where fieldnames are duplicated?

开发者 https://www.devze.com 2022-12-12 04:21 出处:网络
I am using SQL. Here is an example of my table: (There are actually thousands of rows like these, with varying course numbers.)

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

精彩评论

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