是否有公式在多个查询之前和之间放置字符串?

时间:2019-07-19 16:45:19

标签: google-sheets google-sheets-formula google-sheets-query

我要合并多个查询,但需要在每个查询之间插入一个字符串。我已经编写了用于组合多个查询的公式,但是无法弄清楚如何在查询周围放置字符串。图像右侧的所需结果:

example data with desired result

我尝试了串联,但是它将整个查询放入一个单元格中。我已经试过花括号了,但是出现了公式解析错误。

示例1:工作查询,但不尝试包含字符串(图像中的测试结果):

={QUERY(F6:H17,"select G, F where H = 1");QUERY(F6:H17,"select G, F where H = 2");QUERY(F6:H17,"select G, F where H = 3");QUERY(F6:H17,"select G, F where H = 4")}

示例2:串联导致查询位于一个单元格中:

=CONCATENATE("box 1",{QUERY(F6:H17,"select G, F where H = 1");QUERY(F6:H17,"select G, F where H = 2");QUERY(F6:H17,"select G, F where H = 3");QUERY(F6:H17,"select G, F where H = 4")})

示例3:使用大括号将字符串与查询结合-公式解析错误:

={"box 1",QUERY(F6:H17,"select G, F where H = 1");"box 2; "QUERY(F6:H17,"select G, F where H = 2");"box 3"; QUERY(F6:H17,"select G, F where H = 3");"box 4;"QUERY(F6:H17,"select G, F where H = 4")}}

我希望将字符串按编码放置在查询之前和之后,但是我得到了许多不同类型的结果。

1 个答案:

答案 0 :(得分:1)

我认为您的第一次尝试非常接近,只是缺少标签:

={QUERY(F6:H17,"select G, F where H = 1 label G 'box 1'");QUERY(F6:H17,"select G, F where H = 2 label G 'box 2'");QUERY(F6:H17,"select G, F where H = 3 label G 'box 3'");QUERY(F6:H17,"select G, F where H = 4 label G 'box 4'")}