I’m working on an assignment for class. I need to write an SQL statement that returns every single country in the database where no single ethnic group makes up more than 25% of the population. This is the closest I can get:
SELECT * FROM ethnicgroup WHERE percentage < 25;
But, that only returns records where ethnic groups are over 25% population. It doesn’t remove other rows in the table where a different ethnic group for the same country is under 25%.
The table looks like this (I limited the snippet below to 10 entires. It’s much, MUCH bigger.):
country | name | percentage ---------+------------+------------ AL | Albanian | 97 AL | Greek | 0.9 AL | Macedonian | 0.9 AL | Roma | 0.3 AL | Aromanian | 0.3 GR | Greek | 91 GR | Albanian | 4.4 GR | Roma | 2 GR | Macedonian | 1.5 GR | Turkish | 1
Advertisement
Answer
I think you are looking for this
SELECT country FROM ethnicgroup GROUP BY country HAVING MAX(percentage)<25