我注意到 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 子句中。谁能提供一个理由?