I have a dataframe which i want to group by specific columns and then select only rows with multiple values (> 1) in colum FieldID_distinct. Goal is to find distinct FieldID with same DateTime, SerialNumber, geometry, FarmName, FieldName.
My query
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
I tried
where FieldID_distinct> 2
and
having FieldID_distinct> 2
but failed.
for Oracle you have to make use of count() function having count(FieldID_duplicate) >2.
You can just count the values in a having
clause:
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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.