我在MySQL中创建一个支点时遇到问题
我有下表;
Month,id,name,partner,amount
01,1,xx,AA,100
01,1,xx,BB,200
我希望从此表中获得以下输出
Month,id,name,partner,amount ,partner, amount
01,1,XX,A,100,BB,200
我尝试了不同的分组,但我无法将两行转换为一行。
答案 0 :(得分:0)
接近你想要的东西(只有输出不分成字段) - 未经测试
SELECT MONTH, ID, NAME,
GROUP_CONCAT(INFO ORDER BY PARTNER SEPARATOR ',') AS INFO_LIST FROM (
SELECT MONTH, ID, NAME, PARTNER,
CONCAT_WS(',', PARTNER, AMOUNT) as INFO FROM <yourtable>
) GROUP BY MONTH, ID ORDER BY MONTH, ID;