我在Google表格中有一个查询如下:
=Query('Final Tracker'!B:G, "Select Col1, Col2, Col3, Col5, Col4, Col6 Where Col3='Credit Card payment' OR Col6='Credit Card'", 0)
它按预期工作,也就是说所有返回的行都按指定的顺序排序,但我需要修改查询,以便它根据返回结果的列更改列的排序顺序:
If Col3 = "Credit Card payment" the sort order should be Col1, Col2, Col3, Col5, Col4, Col6
but if Col6 = "Credit Card" the sort order should be Col1, Col2, Col3, Col4, Col5, Col6
如果 Col6 =“信用卡”,则 Col3 永远不会等于“信用卡付款”。
如何修改查询以适应不同的排序顺序?
使用
byrow()
和 if()
,如下所示:
=let(
data, query('Final Tracker'!B:G, "where Col3 = 'Credit Card payment' or Col6 = 'Credit Card'", 0),
byrow(data, lambda(row, if(
choosecols(row, 3) = "Credit Card payment",
choosecols(row, 1, 2, 3, 5, 4, 6),
row
)))
)