gpt4 book ai didi

mysql - 在 MySQL 中连接两个 group_concat 查询

转载 作者:行者123 更新时间:2023-11-29 19:18:25 26 4
gpt4 key购买 nike

我想做的事情很奇怪!我想要 group_concat 按两个不同列分组的列值之一。这会给我两个结果,每个结果有两列。之后,我想加入并连接这两个结果中的 group_concat 值,以便我可以找到一个结果。我的 table

x  y1  y2
----------
a 1 2
b 2 3
c 4 3

我想要类似的东西

x     y
----------
a 1
a,b 2
b,c 3
c 4

我可以使用两个不同的查询对按 y1 和 y2 分组的 x 值进行 group_concat。我无法同时加入和连接它们。帮助我。

最佳答案

我认为您只想使用union all“取消透视”数据,然后进行聚合:

select y, group_concat(x) as xs
from ((select x, y1 as y from t
) union all
(select x, y2 as y from t
)
) t
group by y

关于mysql - 在 MySQL 中连接两个 group_concat 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42578651/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com