1

我正在尝试使用 query() 函数在 Google 电子表格中构建报告。我想使用 dateDiff() 和 avg() 函数选择平均日期差。

这是我的查询:

select avg(dateDiff(A, B))

这是我要从中选择的表:

+---------------------+---------------------+
|          A          |           B         |
+---------------------+---------------------+
| 01/08/2013 15:41:00 | 31/07/2013 13:35:00 |
+---------------------+---------------------+
| 31/07/2013 17:17:00 | 31/07/2013 09:57:00 |
+---------------------+---------------------+
| 06/08/2013 15:14:00 | 29/07/2013 13:50:00 |
+---------------------+---------------------+

这是我收到的错误消息:

error: Invalid query: Query parse error: Encountered " "(" "( "" at line 1, column 20. Was expecting: ")" ...

这是我一直在处理的电子表格的打开副本。 https://docs.google.com/spreadsheet/ccc?key=0AhEoOqMhLAGbdEE1ZkhqSjlDT0lYVnVhY3hjNmlWZ3c#gid=0

甚至可以使用 query() 函数吗?

4

1 回答 1

1

If I'm understanding correctly, you require a single average of all the date differences. In which case it would be best to use the AVERAGE spreadsheet function outside the QUERY function.

=AVERAGE(QUERY(A1:B3;"select datediff(A,B) label datediff(A,B) ''"))

It actually isn't really necessary to put the label datediff(A,B) '' as the AVERAGE function will ignore the text header populated by the QUERY, but I put it in for the sake of completeness.

于 2013-08-13T00:43:32.667 回答