SQL题集解答-1

推荐一个很好的SQL在线测试网站 链接直达

1.The example uses a WHERE clause to show the population of 'France'. Note that strings (pieces of text that are data) should be in 'single quotes';
Modify it to show the population of Germany

SELECT population FROM world
WHERE name = 'France'

2.The query shows the name and population density for each country where the area is over 5,000,000 km2. Population density is not a column in the World table, but we can calculate it as population/area.
Modify it to show the name and per capita gdp: gdp/population for each country where the area is over 5,000,000 km2

SELECT name, gdp/population FROM world
WHERE area > 5000000

3.Checking a list The word IN allows us to check if an item is in a list. The example shows the name and population for the countries 'Luxembourg', 'Mauritius' and 'Samoa'.
Show the name and the population for 'Ireland', 'Iceland' and 'Denmark'.

SELECT name, population FROM world
  WHERE name IN ('Ireland','Iceland', 'Denmark');

4.Which countries are not too small and not too big? BETWEEN allows range checking (range specified is inclusive of boundary values). The example below shows countries with an area of 250,000-300,000 sq. km. Modify it to show the country and the area for countries with an area between 200,000 and 250,000.

SELECT name, area FROM world
  WHERE area BETWEEN 200000 AND 250000
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容