gpt4 book ai didi

mysql - 如何以逗号分隔获取重复的列值

转载 作者:行者123 更新时间:2023-12-01 00:21:40 28 4
gpt4 key购买 nike

<分区>

我有一张这样的 table

+----+------------+------------+---------+-----+------+------+
| id | is_deleted | sort_order | version | cid | pid | qid |
+----+------------+------------+---------+-----+------+------+
| 1 | | 1 | 0 | 1 | 1 | 1 |
| 2 | | 2 | 0 | 1 | 1 | 2 |
| 3 | | 3 | 0 | 1 | 1 | 3 |
| 4 | | 1 | 0 | 1 | 2 | 7 |
| 5 | | 2 | 0 | 1 | 2 | 1 |
| 6 | ☺ | 1 | 1 | 1 | 6 | 14 |
| 7 | ☺ | 1 | 1 | 1 | 5 | 13 |
| 8 | | 1 | 0 | 1 | 4 | 12 |
| 9 | | 3 | 0 | 1 | 2 | 2 |
| 10 | | 4 | 0 | 1 | 1 | 4 |
| 11 | | 5 | 0 | 1 | 1 | 5 |
+----+------------+------------+---------+-----+------+------+

如您所见,pid 是重复的。是否有可能得到如下格式

pid      qid
1 1,2,3,4,5
2 7,1,2
6 14
5 13
4 12

我这样试过,但我得到的输出是

SELECT pid,GROUP_CONCAT(qid) FROM client_parent_question

------+--------------------------+
pid | GROUP_CONCAT(qid) |
------+--------------------------+
1 | 1,2,3,7,1,14,13,12,2,4,5 |
------+--------------------------+

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