2

我注意到 BQL 不允许我在 WHERE 或 HAVING 子句中引用范围聚合。例如:

% bq query 'SELECT fullName, COUNT(children.name) WITHIN RECORD as numChildren FROM [persons.person]'  
+---------------+-------------+
|   fullName    | numChildren |
+---------------+-------------+
| John Doe      |           2 |
| Mike Jones    |           3 |
| Anna Karenina |           0 |
+---------------+-------------+

% bq query 'SELECT fullName, COUNT(children.name) WITHIN RECORD as numChildren FROM [persons.person] WHERE numChildren > 0'  
BigQuery error in query operation: Field 'numChildren' not found in table 'persons.person'.

% bq query 'SELECT fullName, COUNT(children.name) WITHIN RECORD as numChildren FROM [persons.person] HAVING numChildren > 0' 
BigQuery error in query operation: Invalid use of HAVING clause. HAVING should be used only when non scoped aggregations are present. Non aggregating queries should use WHERE instead

我理解在 WHERE 子句中不允许组级聚合的理由,以及在 WHERE 或 HAVING 子句中不允许表级聚合的理由,但我想不出任何理由乳清范围聚合可以'不会出现在 WHERE 或 HAVING 子句中。谁能提供一个理由?

4

2 回答 2

2

似乎您应该能够在 HAVING 子句中执行此操作。这已添加到我们关于潜在 BigQuery SQL 语言改进的内部文档中。

于 2013-10-01T04:41:54.647 回答
0

好消息:现在有效。

SELECT created_at, COUNT(payload.shas.actor_email) WITHIN RECORD AS xx
FROM [publicdata:samples.github_nested]
HAVING xx>1
LIMIT 10
于 2014-08-13T01:57:42.950 回答