11.21 MySQL学习记录

2017-11-21 17:51:04


select *
from world.city;

select countrycode
from world.city;

/*distinct关键字作用于所有列,不仅仅跟着的后面那列*/
select distinct countrycode
from world.city;


/*检索前五行数据*/
select district
from world.city
limit 5;


/*从第十行开始,检索五行数据*/
select district
from world.city
limit 10,5;

/*按照字母顺序排列*/
select Name
from world.city
order by name;

/*先按GNP排列 再按Continent排列 (order by 2,3可以达到同样的效果,但更改时候容易出错)*/
select name, GNP, Continent
from world.country
order by GNP, Continent;

/*想在多个列上进行降序,需要在目标列后加desc*/
select name, region, population
from world.country
order by population desc;

/*order by语句需要放在where语句之后*/
select name, region, population
from world.country
where population >= 1000000
order by population;

select name, region, population
from world.country
where population between 5000000 and 10000000;

/*and关键字链接两个条件 or关键字满足其中一个条件就可以把数据返回*/
select name, district, population
from world.city
where CountryCode = 'PHL' and Population >= 400000

/*任何时候使用具有or和and操作符的where字句,都应该使用圆括号)*/
select name, district, population
from world.city
where (CountryCode = 'PHL' or CountryCode = 'BRA' )
and Population >= 400000

 

posted on 2017-11-21 17:52  vincenthe1  阅读(198)  评论(0)    收藏  举报

导航