SELECT name FROM world WHERE population>200000000;
查询大于2亿人口的国家,及国内生产总值
SELECT name,gdp/population FROM world WHERE population >200000000;
查询在South America南美洲的国际爱和以百万为单位的人口數
SELECT name,population /1000000 FROM world WHERE continent ='South America';--别忘记单引号,代表字符串
查询法国,德国,意大利(France, Germany, Italy)的国家名称和人口
SELECT name,population FROM world WHERE name in ('France', 'Germany', 'Italy')--别忘记单引号,代表字符串
查询包含单词“United”的国家
SELECT name FROM world WHERE name LIKE'%United%';
查询大国(面积大于300万平方公里或者人口大于2.5亿)的名字,面积,人口
SELECT name,population,area FROM world WHERE area >3000000 OR population >250000000;
美国,印度,中国(USA, India, China)是人口又大,同时面积又大的國家。排除这些国家。
顯示以人口或面积为大国的國家,但不能同时面积大且人口多的国家名称,人口,面积。
SELECT name,population,area FROM world WHERE (area >3000000AND population <250000000) OR (area <3000000AND population >250000000);
查询并显示南美洲国家以百万计人口和10亿计gdp(保留小数点2位)。
SELECT name,ROUND(population/1000000,2),ROUND(gdp/1000000000,2) FROM world WHERE continent ='South America'; /*ROUND 函数用于把数值字段舍入为指定的小数位数。 SELECT ROUND(column_name,要保留的位数) FROM table_name*/
查找国家和大洲,但是用Eurasia代替Europe和Asia; 用America代替在 North America 或者South America或者Caribbean的国家. 且国家名字要以A或者B开头。
SELECT name, CASEWHEN continent ='Europe'THEN'Eurasia' WHEN continent ='Asia'THEN'Eurasia' WHEN continent in ('North America','South America','Caribbean') THEN'America' ELSE continent END FROM world WHERE name LIKE'A%'OR name LIKE'B%';
Put the continents right…
Oceania becomes Australasia
Countries in Eurasia and Turkey go to Europe/Asia
Caribbean islands starting with ‘B’ go to North America, other Caribbean islands go to South America
Show the name, the original continent and the new continent of all countries.
SELECT name, continent, CASE WHEN continent ='Oceania'THEN'Australasia' WHEN continent IN ('Eurasia', 'Turkey') THEN'Europe/Asia' WHEN continent ='Caribbean'AND name LIKE'B%'THEN'North America' WHEN continent ='Caribbean'THEN'South America' ELSE continent END FROM world ORDERBY name;
查询诺贝尔奖
查询1950年诺贝尔奖的所有资料。
SELECT yr, subject, winner FROM nobel WHERE yr =1950;
查询1962年谁获得了诺贝尔文学奖(Literature)。
SELECT winner FROM nobel WHERE yr =1962AND subject ='Literature';
查询爱因斯坦”(‘Albert Einstein’) 的获奖年份和奖项
SELECT yr,subject FROM nobel WHERE winner ='Albert Einstein';
查询2000年及以后的诺贝尔奖和平奖(Peace)获得者
SELECT winner FROM nobel WHERE yr >=2000AND subject ='Peace';
查询1980到1989(包含首尾)的诺贝尔文学奖获得者的所有资料
SELECT yr,subject,winner FROM nobel WHERE (yr >=1980AND yr <=1989) AND subject ='Literature';
查询总统获得者的所有细节–Theodore Roosevelt;Woodrow Wilson; Jimmy Carter;
SELECT* FROM nobel WHERE winner IN ('Theodore Roosevelt', 'Woodrow Wilson', 'Jimmy Carter')