I have a table called country with a column called population. I need to get a table with only the highest and lowest population country. I have tried:
select max(population) from country;
select min(population) from country;
but I can't figure out how to combine these queries into only one query.
Best wishes!
答案 0 :(得分:2)
select min(population), max(population) from country;
Will get you a result with two columns, the first holding the minimum population and the second the maximum population.
That only returns the populations though. If what you need is a query that will return the two countries, embedded queries would do :
select * from country where population=(select min(population) from country) or population=(select max(population) from country);
答案 1 :(得分:0)
试试这个:
select country,min(population) from country
group by 1
Union
select country,max(population) from country
group by 1
order by 1;