By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table t
as
select *
from (values
row(1, 'NY'),
row(3, 'NY'),
row(null, 'LA')
) as t(lat, state)
select state, avg(lat) as alat
from t
group by state
state | alat |
---|---|
NY | 2.0000 |
LA | null |
/*No input rows - empty*/
select avg(lat)
from t
where state = 'AR'
group by state
/*There's input row,
but the avg is empty - empty output*/
select avg(lat)
from t
where state = 'LA'
group by state
avg(lat) |
---|
null |
/*There's a row and avg is empty,
but we filter it out with having*/
select avg(lat)
from t
where state = 'LA'
group by state
having avg(lat) is not null