具有 OR 条件的 QUERY 函数 >查询表,选择 E,其中 C 包含 Cell1 *OR* Cell2 limit 1

发布于 2025-01-16 00:49:02 字数 935 浏览 1 评论 0原文

我尝试在以下查询中使用 OR 运算符。

这个想法是,单元格将显示来自分支的里程。用户可以选择 C12 或 E12 处的分支,单元格将显示表中的里程。我的下一步是制作一个 if 语句,但我想知道是否有可能使其像这样工作

=iferror(query(BranchesHrsKms, "Select E where C matches'"&C12&"' or C matches'"&E12&"'limit 1",0),"")`

当前代码的作用:基本上只是运行这部分

C matches'"&E12&"'limit 1",0),"")

,但仅当 C12 中有内容时才运行。

任何指导表示赞赏

更新: 它可以与If和ISBLANK一起使用

=IF(ISBLANK(C16)=FALSE, iferror(query(BranchesHrsKms, 
"Select E where C matches'"&C16&"' limit 1",0),""), 
iferror(query(BranchesHrsKms, "Select E where C matches'"&E16&"' limit 1",0),""))

要使用的工作表副本:https://docs.google.com/spreadsheets/d/1fn5xzWi47xcgnQiDk5v_t1UDtIF6gHKGB4WoblbT3-Y/edit#gid=686684908

I am attempting to use OR operator in the following Query.

The idea is that the cell will display mileage from a branch. The user can select a branch at either C12 or E12, and the cell will display the mileage from the table. My next move would be to make an if statement but I'm wondering if its possible to make it work like this

=iferror(query(BranchesHrsKms, "Select E where C matches'"&C12&"' or C matches'"&E12&"'limit 1",0),"")`

What the current code does: Basically just runs this part

C matches'"&E12&"'limit 1",0),"")

But only when there is something in C12.

Any guidance appreciated

Update:
It can work with If and ISBLANK

=IF(ISBLANK(C16)=FALSE, iferror(query(BranchesHrsKms, 
"Select E where C matches'"&C16&"' limit 1",0),""), 
iferror(query(BranchesHrsKms, "Select E where C matches'"&E16&"' limit 1",0),""))

Copy of sheet to play with: https://docs.google.com/spreadsheets/d/1fn5xzWi47xcgnQiDk5v_t1UDtIF6gHKGB4WoblbT3-Y/edit#gid=686684908

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼前雾蒙蒙 2025-01-23 00:49:02

尝试:

=IFERROR(QUERY(BranchesHrsKms, 
 "select E 
  where C matches '.*"&TEXTJOIN(".*|.*", 1, C12, E12)&".*' 
  limit 1", ))

更新:

=INDEX(IFERROR(1/(1/(
 IFNA(VLOOKUP(C10:C23, BranchCodes!C:E, 3, ))+
 IFNA(VLOOKUP(E10:E23, BranchCodes!C:E, 3, ))))))

在此处输入图像描述

try:

=IFERROR(QUERY(BranchesHrsKms, 
 "select E 
  where C matches '.*"&TEXTJOIN(".*|.*", 1, C12, E12)&".*' 
  limit 1", ))

update:

=INDEX(IFERROR(1/(1/(
 IFNA(VLOOKUP(C10:C23, BranchCodes!C:E, 3, ))+
 IFNA(VLOOKUP(E10:E23, BranchCodes!C:E, 3, ))))))

enter image description here

九局 2025-01-23 00:49:02

limit 之前缺少空间

=iferror(query(BranchesHrsKms, "Select E where C contains '"&C12&"' or C contains '"&E12&"' limit 1",0),"")

There is a lack of space before limit

=iferror(query(BranchesHrsKms, "Select E where C contains '"&C12&"' or C contains '"&E12&"' limit 1",0),"")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文