gpt4 book ai didi

mysql - 如何在MySQL中从select where group by中进行选择?

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

我正在尝试按列进行选择和分组,但将其他列与所有行一起保留。我收到错误消息:#1242 - 子查询返回超过 1 行

我的 table

This is my table

我想要的结果

enter image description here

以下是我的查询:

SELECT name FROM table WHERE (SELECT pro_id FROM table GROUP BY pro_id)

最佳答案

尝试这个查询:

SELECT Pro_id
, GROUP_CONCAT(Name SEPARATOR ', ') AS Name
FROM MyTable
GROUP BY Pro_ID;

结果:

| PRO_ID |         NAME |
-------------------------
| 1 | john, sandra |
| 2 | jeo |
| 3 | bruno, piter |

参见this SQLFiddle

关于mysql - 如何在MySQL中从select where group by中进行选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18097673/

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