简体   繁体   中英

SQL Query to concatenate row values based on condition

I am in need of concatenating row values based on a condition in SQL Consider the following table在此处输入图像描述

I want to concatenate value(Column3) where the Column1 contains "runs" along with "total" and group by Column2 .

My expected output is在此处输入图像描述

An example solution in MSSql:

SELECT r1.Column2 AS 'Column1', CONCAT(r1.Column3, ',', r2.Column3) AS Result
FROM Table r1
JOIN Table r2 ON r1.Column2 = r2.Column2
WHERE r1.Column1 LIKE '%Run%' AND r2.Column1 LIKE '%Total%'

Try this:

select Column3, GROUP_CONCAT(Column2) ac from Tablename group by Column2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM