Supposing I have a table and query:
consisting of population for a given country in a given continent for a given year.
i want to return countries avg(population) & the continents avg population if the country's population is greater than the continents +3 Basically I want to filter out rows that are a certain difference away from the subtotal continent value.
I modified this and realize the data does not have multiple years and that the numbers are obviously garbage, but this is just an example.
create table abc (continent varchar2(30), country varchar2(30), population number, yr number)
insert into abc values ('africa', 'kenya', 50, 2005)
insert into abc values ('africa', 'egypt', 100, 2006)
insert into abc values('africa', 'south africa', 35, 2007)
insert into abc values ('africa', 'nigeria', 200, 2008)
insert into abc values ('asia', 'china', 50, 2005)
insert into abc values ('asia', 'india', 100, 2006)
insert into abc values('asia', 'japan', 35, 2007)
insert into abc values ('asia', 'korea', 200, 2008)
select continent, country, avg(population)
from abc
where ------population for each country > 3+ avg for each continent
----should return egpyt/nigeria rows and india/korea rows since average here is 96.25 for each continent.
group by rollup(continent, country)