![](/img/trans.png)
[英]Combine multiple rows into one row MySQL and split value from one field to two in same Query
[英]Combine multiple rows (of one column) from mysql request into one field
如果可能的话,我想将一个查询的结果收集到一个字段中。
请求是:
select group_concat(col1) from table1
group by col3, col2
having count(*)>1
结果是这样的:
'123','124','125'
'123','125'
'126','127'
'123','127'
我正在寻找的结果:
'123','124','125','123','125','126','127','123','127'
我试图再次使用我的group_concat
,concat功能,或将整个查询作为子查询使用,但没有成功...
您正在寻找的GROUP_CONCAT
聚合函数。 但是您需要再次将中间结果分组。
显然您已经尝试过了,但是由于您没有发布查询,因此我将其提供给您:
select group_concat(col1intermediate) as col1total
from
(select group_concat(col1) as col1intermediate
from table1
group by col3, col2
having count(*)>1) as alias_subquery
我不知道为什么您自己的尝试失败了。 也许您忘了向聚合列添加别名(col1intermediate)?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.