Google Query Language似乎缺乏与SQL的“IN”等效的功能。

huangapple go评论62阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年4月17日 01:35:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76029347.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定