如何正确排序此查询?

时间:2019-04-14 21:15:37

标签: google-sheets google-sheets-query

I have this demo sheet

我需要按M列对I3单元格中的查询正确排序

我有这个公式

=ArrayFormula(IFERROR(QUERY({
IFERROR(QUERY({A3:G},"Select Col1,Col2,Col3,'30',Col5 where Col5 contains 'Days' Label '30' '' ",0),{"","","","",""});
IFERROR(QUERY({A3:G},"Select Col1,Col2,Col3,'60',Col6 where Col6 contains 'Days' Label '60' '' ",0),{"","","","",""});
IFERROR(QUERY({A3:G},"Select Col1,Col2,Col3,'90',Col7 where Col7 contains 'Days' Label '90' '' ",0),{"","","","",""})},
"Select * where Col1 is not null order by Col5",0),""))

我已经尝试了好几个小时没有运气

我根据需要制作了一个标签,预期结果

2 个答案:

答案 0 :(得分:0)

  • 字符串按字典顺序排序,即19 Days之前的2 Days为1 <2
  • 从cols5、6和7中的数字中删除Days,您的查询将正常运行。
  • 您可以稍后为它们加上标签:
=ArrayFormula(IFERROR(QUERY({
IFERROR(QUERY({A3:G},"Select Col1,Col2,Col3,'30',Col5 where Col5 contains 'Days' Label '30' '' ",0),{"","","","",""});
IFERROR(QUERY({A3:G},"Select Col1,Col2,Col3,'60',Col6 where Col6 contains 'Days' Label '60' '' ",0),{"","","","",""});
IFERROR(QUERY({A3:G},"Select Col1,Col2,Col3,'90',Col7 where Col7 contains 'Days' Label '90' '' ",0),{"","","","",""})},
"Select Col1,Col2,Col3,Col4,Col5 where Col1 is not null format Col5 '0 Days' order by Col5",0),""))
  • 或者,Days应该以2或3位数字输入:19 Days02 Days

答案 1 :(得分:0)

=ARRAYFORMULA(QUERY({IFERROR(QUERY({
IFERROR(QUERY({A3:G},"select Col1,Col2,Col3,'30',Col5 where Col5 contains 'Days' Label '30' '' ",0),{"","","","",""});
IFERROR(QUERY({A3:G},"select Col1,Col2,Col3,'60',Col6 where Col6 contains 'Days' Label '60' '' ",0),{"","","","",""});
IFERROR(QUERY({A3:G},"select Col1,Col2,Col3,'90',Col7 where Col7 contains 'Days' Label '90' '' ",0),{"","","","",""})},
"Select * where Col1 is not null",0),""), 
VALUE(REGEXEXTRACT(IFERROR(QUERY({
IFERROR(QUERY({A3:G},"select Col1,Col2,Col3,'30',Col5 where Col5 contains 'Days' Label '30' '' ",0),{"","","","",""});
IFERROR(QUERY({A3:G},"select Col1,Col2,Col3,'60',Col6 where Col6 contains 'Days' Label '60' '' ",0),{"","","","",""});
IFERROR(QUERY({A3:G},"select Col1,Col2,Col3,'90',Col7 where Col7 contains 'Days' Label '90' '' ",0),{"","","","",""})},
"Select Col5 where Col1 is not null",0),""),"\d+"))}, "select Col1,Col2,Col3,Col4,Col5 order by Col6"))

0