sql列转行(字段)逗号分割

LISTAGG(列名,<分隔符>) WITHIN GROUP(ORDER BY 列名)函数

SELECT D.id,LISTAGG(E.keyword,',') WITHIN GROUP(ORDER BY E.keyword) AS keyword 
FROM STOCK_LIVE D
LEFT JOIN STOCK_KEYWORD E ON D.id = E.SPECIAL_ID where d.id=141211111
GROUP BY D.id 

在这里插入图片描述

WM_CONCAT(列名)函数(速度慢)

SELECT D.id,WM_CONCAT(E.keyword) AS keyword 
FROM STOCK_LIVE D
LEFT JOIN STOCK_KEYWORD E ON D.id = E.SPECIAL_ID where d.id=141211111
GROUP BY D.id 

二者效果一样,但是wm_concat我测试得时候速度特别慢

你可能感兴趣的:(数据库,sql)