在 Google Sheets 中哪里放置 ORDER BY 来对查询进行排序?

问题描述 投票:0回答:2

我目前有以下公式,可根据用户所做的自定义输入过滤结果。我正在尝试在其上添加排序功能...

但是,我有点迷失在何时应该放置 ORDER BY 函数来允许我执行此操作。我可以在哪里添加 ORDER BY 到此?我的语法不正确吗?

如果这是一个简单的解决方案,请提前道歉,我是 Google 表格的新手。

=QUERY('2 - CC RAW'!1:1000,"SELECT * WHERE 1=1 "&IF(B3="所有相",""," AND LOWER(H) 包含 LOWER('"&B3&"') ")&IF(B4="NONE",""," AND LOWER(L) 包含 LOWER('"&B4&"') ")&IF(ISBLANK(B5),""," AND LOWER(C) 包含 LOWER(' "&B5&"') "), 1)

我尝试将 ORDER BY 函数放置在各个位置,但要么产生错误,要么对查询的数据没有任何反应。

google-sheets sql-order-by
2个回答
0
投票

您可以尝试:

=QUERY('2 - CC RAW'!1:1000,"SELECT * WHERE 1=1 "&
      IF(B3="ALL PHASES",""," AND LOWER(H) CONTAINS LOWER('"&B3&"') ")&
      IF(B4="NONE",""," AND LOWER(L) CONTAINS LOWER('"&B4&"') ")&
      IF(ISBLANK(B5),""," AND LOWER(C) CONTAINS LOWER('"&B5&"') ")&
      "order by C desc,H", 1)
  • 仅供参考
    C
    降序(第一优先级)排序,然后
    H
    升序

0
投票

order by
子句位于
where
子句之后,如下所示:

=query(
  '2 - CC RAW'!A1:Z, 
  "where " & textjoin(" and ", true, 
    "1 = 1", 
    if(B3 = "all phases", "", "lower(H) contains lower('" & B3 & "') "), 
    if(B4 = "none", "", "lower(L) contains lower('" & B4 & "') "), 
    if(isblank(B5), "", "lower(C) contains lower('" & B5 & "') ") 
  ) & 
  "order by A", 
  1 
)

请参阅查询语言帮助页面

© www.soinside.com 2019 - 2024. All rights reserved.