我目前有以下公式,可根据用户所做的自定义输入过滤结果。我正在尝试在其上添加排序功能...
但是,我有点迷失在何时应该放置 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 函数放置在各个位置,但要么产生错误,要么对查询的数据没有任何反应。
您可以尝试:
=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
升序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
)
请参阅查询语言帮助页面。