Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在SQL BigQuery列中选择具有多个值的行_Sql_Google Bigquery - Fatal编程技术网

在SQL BigQuery列中选择具有多个值的行

在SQL BigQuery列中选择具有多个值的行,sql,google-bigquery,Sql,Google Bigquery,我有一个数据框,我想按特定列对其进行分组,然后仅选择列中具有多个值(>1)的行。目标是找到具有相同DateTime、SerialNumber、geometry、FarmName和FieldName的不同FieldID 我的问题 select DateTime, SerialNumber, geometry, FarmName, FieldName, ARRAY_AGG(DISTINCT FieldID) AS FieldID_distinct from `xxx.yyy.zzz` group b

我有一个数据框,我想按特定列对其进行分组,然后仅选择列中具有多个值(>1)的行。目标是找到具有相同DateTime、SerialNumber、geometry、FarmName和FieldName的不同FieldID

我的问题

select DateTime, SerialNumber, geometry, FarmName, FieldName,
ARRAY_AGG(DISTINCT FieldID) AS FieldID_distinct
from `xxx.yyy.zzz`
group by 1,2,3,4,5
order by DateTime ASC
我试过了

where FieldID_distinct> 2   


但是失败了。

对于Oracle,您必须使用count()函数
拥有count(FieldID\u duplicate)>2。

对于Oracle,您必须使用count()函数
having count(FieldID_duplicate)>2。

您可以只计算having子句中的值:

select DateTime, SerialNumber, geometry, FarmName, FieldName,
       ARRAY_AGG(DISTINCT FieldID) AS FieldID_distinct
from `xxx.yyy.zzz`
group by 1, 2, 3, 4, 5
having count(distinct FieldID) > 2
order by DateTime ASC;

您可以只计算
having
子句中的值:

select DateTime, SerialNumber, geometry, FarmName, FieldName,
       ARRAY_AGG(DISTINCT FieldID) AS FieldID_distinct
from `xxx.yyy.zzz`
group by 1, 2, 3, 4, 5
having count(distinct FieldID) > 2
order by DateTime ASC;

我得到的消息是:在[6:14]不允许聚合的聚合,您可以尝试,因为count()>2。在select子句中也包含count()。PS:我认为star在注释中不可见。将count(ARRAY_AGG(DISTINCT FieldID)设置为FieldID_DISTINCT)>1,将返回语法错误:预期“”,但在[2:43]count(*)处获取关键字。。这样的话,我现在更困惑了……你能不能更准确一点,或者用答案中的整个语法来回答?非常感谢。我得到的消息是:在[6:14]不允许聚合的聚合,您可以尝试,因为count()>2。在select子句中也包含count()。PS:我认为star在注释中不可见。将count(ARRAY_AGG(DISTINCT FieldID)设置为FieldID_DISTINCT)>1,将返回语法错误:预期“”,但在[2:43]count(*)处获取关键字。。这样的话,我现在更困惑了……你能不能更准确一点,或者用答案中的整个语法来回答?非常感谢。