gpt4 book ai didi

google-sheets - 将列中的重复行组合为逗号分隔值 - Google 查询

转载 作者:行者123 更新时间:2023-12-05 09:36:23 25 4
gpt4 key购买 nike

如果我有 2 列,即 ID 和名称,ID 列包含重复项,并且如果我想按 ID 分组以获得唯一 ID 但名称列应该是逗号分隔的列表,这在 Google 查询中是否可行?

| ID   | Name |
===============
| 1001 | abc |
---------------
| 1001 | def |
---------------
| 1002 | kjg |
---------------
| 1003 | aof |
---------------
| 1003 | lmi |
---------------
| 1004 | xyz |
---------------

进入

| ID   | Name      |
====================
| 1001 | abc, def |
--------------------
| 1002 | kjg |
--------------------
| 1003 | aof, lmi |
--------------------
| 1004 | xyz |
--------------------

最佳答案

尝试:

=ARRAYFORMULA({QUERY(QUERY({A2:B, B2:B}, 
"select Col1,max(Col2)
where Col1 is not null
group by Col1
pivot Col3"),
"select Col1
offset 1", 0), REGEXREPLACE(TRIM(
TRANSPOSE(QUERY(TRANSPOSE(QUERY(QUERY({A2:B&",", B2:B},
"select max(Col2)
where Col1 is not null
and Col2 <> ','
group by Col1
pivot Col3"),
"offset 1", 0)),,999^9))), ",$", )})

enter image description here

但是,由于 TRIM(需要删除空格)和 REGEXREPLACE(需要删除结尾逗号),这可能不适用于大量数据集限制。否则,没有它,公式可以处理任何事情:

=ARRAYFORMULA({QUERY(QUERY({A2:B, B2:B}, 
"select Col1,max(Col2)
where Col1 is not null
group by Col1
pivot Col3"),
"select Col1
offset 1", 0),
TRANSPOSE(QUERY(TRANSPOSE(QUERY(QUERY({A2:B&",", B2:B},
"select max(Col2)
where Col1 is not null
and Col2 <> ','
group by Col1
pivot Col3"),
"offset 1", 0)),,999^9))})

关于google-sheets - 将列中的重复行组合为逗号分隔值 - Google 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65169246/

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