Google 工作表查询:通过附加值列表替换单元格中的值

Google sheets query: replacing a value in a cell by appending a list of values

我有两个sheet。

一个是不可透视的 sheet,具有组和关联的 ID(即该组中的人员),如下所示:

group id
Group1 ID1
Group2 ID2
Group2 ID4
Group3 ID1
Group3 ID2
Group3 ID3

第二个是房间和有权访问该房间的组:

room1 room2 room3
Group1 Group3 Group1
Group2

我想在新的 sheet 中使用 google 查询获得这样的输出。其中组已被其 ID 替换:

room1 room2 room3
ID1 ID1 ID1
ID2 ID2
ID3 ID4

我的原始数据集有 1000 多个 ID、100 个组和 30 个房间。

Sheet 1:

Sheet 2:

Sheet 3:

单元格 A2 的公式:

=query({Sheet1!$A:$B},"select Col2 where Col1 matches '"&textjoin("|",true,Sheet2!A2:A)&"' ",0)

然后向右拖动,例如单元格B2:

=query({Sheet1!$A:$B},"select Col2 where Col1 matches '"&textjoin("|",true,Sheet2!B2:B)&"' ",0)

单元格 C2:

=query({Sheet1!$A:$B},"select Col2 where Col1 matches '"&textjoin("|",true,Sheet2!C2:C)&"' ",0)