英文:
Google Query Language seems to lack an equivalent to sql's "IN"
问题
我知道match
存在,但我需要运行类似于SELECT foo WHERE bar IN (SELECT baz WHERE qux='quux')
的等价查询。我查看了文档,但没有提到如何实现这样的查询,至少我期望的地方没有(参见此处)。那么,我该如何执行类似这样复杂的查询呢?
英文:
I know that match
exists, but I need to run the equivalent of SELECT foo WHERE bar IN (SELECT baz WHERE qux='quux')
. I have looked at the docuemtation and there is no mention of a way to do this, at least where I would expect it to be (see here). So how can I make complex queries such as this one?
答案1
得分: 1
你可以通过使用管道字符将内部查询结果与JOIN连接,然后使用MATCHES来评估结果数组(它将管道解释为OR)来模仿IN运算符:
=query(array,"select foo where bar matches ''&"join("|",query(array,"select baz where qux='quux'"))&"''")
如果你的内部查询有标题行,你需要在选择字符串的末尾添加 label baz ''
以删除标题,否则你将尝试匹配它。
英文:
You can mimic the IN operator by concatenating the inner query results with JOIN using the pipe character and evaluating the resultant array using MATCHES (which interprets the pipes as ORs):
=query(array,"select foo where bar matches '"&join("|",query(array,"select baz where qux='quux'))&"'")
If your inner query has a header row, you'll need to add label baz ''
to the end of the select string to remove the header otherwise you'll be trying to match that as well.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论