本文介绍了选择查询到一列列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将所有ID都选择到一列中,并以逗号,
I am trying to select all id into one column and delimit it with a comma ,
我的数据列:
+---+--------+--------------+
|id |somedata|someother data|
+---+--------+--------------+
|1 |data1 |other1 |
+---+--------+--------------+
|2 |data2 |other2 |
+---+--------+--------------+
|3 |data3 |other3 |
+---+--------+--------------+
我想要做出的结果:
+-------+
|id list|
+-------+
|1, 2, 3|
+-------+
结果应该是名为"id list"的1列ID的列表.
The result should be a list of ID's in 1 column named 'id list'.
问题是,这可能吗?如何?我尝试搜索关键字sql query select into list
和其他关键字,但是没有运气.
The question is, is this possible? and how? I tried searching for the keywords sql query select into list
and other keywords but with no luck.
但是此查询基于嵌套选择.
But this query is on a nested select.
推荐答案
使用 GROUP_CONCAT() :
SELECT GROUP_CONCAT(id) AS idList FROM tableA
这篇关于选择查询到一列列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!