我想用查询语言得到我需要的数据的行号,例如:选择A,ROW_NUMBER(),其中(B = 1)。
但似乎查询语言不提供如下函数:ROW_NUMBER()?
除了查询整个列并在JavaScript中计算之外,我该怎么做?
答案 0 :(得分:6)
You can add a column with arrayformula(row(...))
to the queried range, and include it in results. Example:
=query({A2:B, arrayformula(row(A2:B))}, "select Col1, Col3 where Col2 = 1")
Here Col1 = A, Col2 = B, Col3 = added column with the row number. Since the array to be queried is constructed within the formula, its columns are referred to as Col1, Col2, and so on.
答案 1 :(得分:1)
关于接受的答案,请记住,某些用户需要从Google文档中进行更改
=query({A2:B, arrayformula(row(A2:B))}, "select Col1, Col3 where Col2 = 1")
到
=query({A2:B\ arrayformula(row(A2:B))}, "select Col1, Col3 where Col2 = 1")
因为数组正弦可以改变(Google Documentation):
注:对于使用逗号作为小数点分隔符的国家(例如, €1,00),则在创建时将逗号替换为反斜杠() 数组。