Google 表格将两个查询合并为一个

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

我在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 永远不会等于“信用卡付款”。

如何修改查询以适应不同的排序顺序?

google-sheets google-sheets-formula
1个回答
0
投票

使用

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 
  ))) 
)
© www.soinside.com 2019 - 2024. All rights reserved.