如何使用query()在googlesheets中建立搜索表单? [英] How to build a search form in googlesheets with query()?
问题描述
请求的行为:
我想在Google表格中创建搜索表单,以查询用作数据库的表格.
Requested behaviour:
I would like to create a search form in Google Sheets to query a table that I use as a database.
- 用户应该能够通过多次搜索来查询表用户可以在工作表的单元格中键入的类别.
- 如果用户未输入搜索字符串,则所有项目应该显示.
- 此外,用户应该可以在包括或"和排除与"搜索.
原始表与搜索表不在同一张纸上.最终的搜索表单应具有10个以上可搜索的类别.
The original table is on a different sheet than the search form. The final searchform should have more than 10 searchable categories.
当前状态
由于原始表与搜索表单不在同一张表中,因此我的想法是通过动态query()函数导入表.
Current State
Since the original table is in a different sheet than the search form, my idea has been to import the table by a dynamic query() function.
我创建了两个输入搜索输入字段,并在其中创建了一个用户可以在或"和与"之间切换的字段.我还创建了一个查询函数,将这3个搜索词连接在一起.或"和与"搜索之间的更改有效(采用第一种方法).
I created two input search input fields and a field where the user can switch between "OR" and "AND". I also created a query function that connects these 3 search terms. The change between "OR" and "AND" search works (with the first approach).
第一种方法:
First approach:
=QUERY('Geschäftsvorfälle'!A2:AG1000, "select * WHERE A="&B4&" "&D1&" B='"&B5&"'")
第二种方法:
Second approach:
=QUERY('Geschäftsvorfälle'!A2:AG1000, "select * " &if(B5="Alle",, "WHERE B='"&B5&"'") &if(B4="",, "WHERE A="&B4&""))
问题
第一种方法适用于"OR"搜索,但是如果我使用多个搜索词,则会返回空白表.如果将一个搜索词留空,也会引发"VALUE"错误.如果我使用多个搜索字词,即使应该有匹配的行,第二种方法也会引发"VALUE"错误.
Issue
The first approach works with the "OR" search but gives an empty sheet back if I use multiple search terms. It also throws a "VALUE" error if leave one search term blank. The second approach throws a "VALUE" error if I use multiple search terms even there should be matching rows.
是否可以在Google表格中使用这种搜索表单?如果是,是否可以使用 query()
进行操作,我该怎么做?您能否提供一些示例屏幕截图或代码?
Is there a way to make this kind of a searchform work in Google Sheets? If yes is it possible to do it with query()
and how do I do it? Could you provide some example screenshots or code?
屏幕截图
搜索表单:
Screenshots
The searchform:
合并查询:
推荐答案
尝试:
=QUERY('Geschäftsvorfälle'!A2:AG,
"where "&TEXTJOIN(" "&D1&" ", 1,
IF(B4<>"", " A="&B4, ),
IF(B5<>"", " B='"&B5&"'", ),
IF(B6<>"", " lower(F) contains '"&LOWER(B6)&"'", )), 1)
这篇关于如何使用query()在googlesheets中建立搜索表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!