赞
踩
Get to the points first. The article comes from LawsonAbs!
#建表
create table myworld(
country varchar(255),
population varchar(255)
)
#插入数据,注意如果你的数据库字符集不是utf8,那么下面的插入语句会出错
insert into mydatabase.myworld VALUES
("英国","200"),
("法国","300"),
("日本","250"),
("德国","200"),
("墨西哥","50"),
("印度","250"),
("中国","600");
select *
from mydatabase.myworld;
插入新的一列(state)
ALTER TABLE mydatabase.myworld add state VARCHAR(10) not NULL
desc mydatabase.myworld
根据每个国家的地理位置添加所在洲
update mydatabase.myworld
set state='亚洲'
where country in ('中国','日本','印度');
update mydatabase.myworld
set state='欧洲'
where country in ('英国','法国','德国');
update mydatabase.myworld
set state='南美洲'
where country in ('美国','墨西哥');
select state,sum(population)
from mydatabase.myworld
group by state; #根据不同的洲名来分组
select state,sum(population) as totalPopulation
from mydatabase.myworld
where state = "亚洲";#只选择亚洲的国家
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。