select *
from world.country;
/*新建一列,upper将文本全部转为大写 lower全部转为小写*/
select district, upper(district) as district_upcase
from world.city
order by district;
/*求某一特定列的平均值*/
select avg(lifeexpectancy) as avg_life
from world.country
where continent = 'africa';
/*计算该行的列数*/
select count(Name) as num_name
from world.country;
/*计算总和*/
select sum(population) as sum_poplulation
from world.country
where continent = 'asia'
/*第十课 分组数据*/
/*group by子句根据continent排序并分组, 会对每一个continent而不是整个表计算total_number*/
select continent, count(*) as total_num
from world.country
group by continent;
/*having过滤分组;where过滤行。having过滤大于拥有30个国家的Continent组*/
select Continent, count(*) as num_country
from world.country
group by Continent
having count(*) >= 30;