如何编写SQL以将来自多个列和行的数据合并为一行。
OrganizationId Name Type Active
--------------------------------------
1 Baker County Yes
2 curry county Yes
预期结果:
SomeColumnName
-------------------------------
1BakerCountyYes2currycountyYes
答案 0 :(得分:0)
<强>的MySQL 强>
使用 GROUP_CONCAT 。
SELECT row_id,
group_concat( Value ORDER BY Value SEPARATOR ' ')
FROM
(SELECT
@row_number:=1 AS row_id,
CONCAT(OrganizationId ,Name,Type,Active) AS Value
FROM
Table1
ORDER BY file_fields_id
) T
GROUP BY row_id;