最近正好在学SQL的基本操作,整理了一下SQLZOO上面的练习和答案,供大家参考~
一、SELECT basics
Modify it to show the population of Germany
2. IN用法,IN后是一个查询,数组
Show thename and the population for 'Sweden', 'Norway' and 'Denmark'.
3. BETWEEN用法
Modify it to show the country and the area for countries with an area between 200,000 and 250,000.
quiz答案:3 5 5 3 3 3 3
二、SELECT from WORLD Tutorial
1.
Observe the result of running this SQL command to show the name, continent and population of all countries.
2.
Show the name for the countries that have a population of at least 200 million. 200 million is 200000000, there are eight zeros.
3. per capita GDP代表人均GDP,人均GDP=GDP/population
Give thename and the per capita GDP for those countries with a population of at least 200 million.
4.
Show thename and population in millions for the countries of the continent 'South America'. Divide the population by 1000000 to get population in millions.
5.
Show thename and population for France, Germany, Italy
6. LIKE谓词的用法,用来表示字符串的部分一致查询(模糊匹配),跟通配符“%”一起用
Show the countries which have aname that includes the word 'United'
7. OR运算符
Two ways to be big: A country isbig if it has an area of more than 3 million sq km or it has a population of more than 250 million. Show the countries that are big by area or big by population. Show name, population and area.
8. AND运算符的优先级高于OR运算符。想要优先执行OR运算符时可以使用括号。
Exclusive OR (XOR). Show the countries that are big by area or big by population but not both. Show name, population and area.
9. ROUND四舍五入:ROUND(对象数值,保留小数的位数)
Show thename and population in millions and the GDP in billions for the countries of the continent 'South America'. Use the ROUND function to show the values to two decimal places.
10. ROUND(参数,小数位数),小数位数为负值时,代表
Show thename and per-capita GDP for those countries with a GDP of at least one trillion (1000000000000; that is 12 zeros). Round this value to the nearest 1000. Show per-capita GDP for the trillion dollar countries to the nearest $1000.
或者
11. LENGTH(参数)表示参数的长度
Show the name and capital where the name and the capital have the same number of characters.
12. LEFT(s,n)允许从字符串s的开头提取n个字符
Show the name and the capital where the first letters of each match. Don't include countries where the name and the capital are the same word.
13.
Find the country that has all the vowels and no spaces in its name.
quiz答案:5 4 2 4 2 4 3
三、SELECT from Nobel Tutorial
Change the query shown so that it displays Nobel prizes for 1950.
2.
Show who won the 1962 prize for Literature.
3.
Show the year and subject that won 'Albert Einstein' his prize.
4.
Give the name of the 'Peace' winners since the year 2000, including 2000.
5.
Show all details (yr, subject, winner) of the Literature prize winners for 1980 to 1989 inclusive.
6.
Show all details of the presidential winners: Theodore Roosevelt, Woodrow Wilson, Jimmy Carter, Barack Obama
7.
Show the winners with first name John
8.
Show the year, subject, and name of Physics winners for 1980 together with the Chemistry winners for 1984.
9.
Show the year, subject, and name of winners for 1980 excluding Chemistry and Medicine
10.
Show year, subject, and name of people who won a 'Medicine' prize in an early year (before 1910, not including 1910) together with winners of a 'Literature' prize in a later year (after 2004, including 2004)
11.
Find all details of the prize won by PETER GRÜNBERG
12. 不能直接在引号字符串中放入单引号。可以在带引号的字符串中使用两个单引号
Find all details of the prize won by EUGENE O'NEILL
13. 未指定ORDER BY子句中排列顺序时会默认使用升序进行排列,使用DESC关键字可以进行降序排序
List the winners, year and subject where the winner starts with Sir. Show the the most recent first, then by name order.
14.subject IN ('Chemistry','Physics')的值也可以表示为0或1
Show the 1984 winners and subject ordered by subject and winner name; but list Chemistry and Physics last.
quiz答案:5 3 2 3 3 3 4
四、SELECT within SELECT Tutorial
List each country name where the population is larger than that of 'Russia'.
2.
Show the countries in Europe with a per capita GDP greater than 'United Kingdom'.
3.
List the name and continent of countries in the continents containing either Argentina or Australia. Order by name of the country.
4.
Which country has a population that is more than Canada but less than Poland? Show the name and the population.
5. CONCAT(s1, s2 ...) ,将两个或多个字符串粘在一起
Show the name and the population of each country in Europe. Show the population as a percentage of the population of Germany.
6. 我们可以使用单词ALL来允许> =或>或<=来对列表进行操作。
Which countries have a GDP greater than every country in Europe? [Give the name only.] (Some countries may have NULL gdp values)
7.
Find the largest country (by area) in each continent, show the continent, the name and the area:
8.
List each continent and the name of the country that comes first alphabetically.
9.
Find the continents where all countries have a population <= 25000000. Then find the names of the countries associated with these continents. Show name, continent and population.
10.
Some countries have populations more than three times that of any of their neighbours (in the same continent). Give the countries and continents.
quiz答案:3 2 1 4 2 2 2
温馨提示:内容为网友见解,仅供参考
SQL入门练习——SQLZOO练习整理(一)
一、SELECT basics Modify it to show the population of Germany 2. IN用法,IN后是一个查询,数组 Show thename and the population for 'Sweden', 'Norway' and 'Denmark'.3. BETWEEN用法 Modify it to show the country and the area for countries with an area between 200,000 and 250,...
SqlZoo练习总结
列出所有与Art Garfunkel合作过的人。SQL学习易于上手,当前初步入门阶段,接下来将深入阅读《SQL必知必会》,并实践安装MySQL进行练习。
SQLZOO刷题(一)
48. 列出演员"Julie Andrews"参与过的电影及其作为第1主角的电影。49. 检查是否有重复电影名称如"Little Miss Marker"。50. 显示按字母顺序,哪位演员曾在30次以上担任第1主角。51. 显示1978年首映电影的名称和角色数量,按角色数量排序。52. 列出与演员"Art Garfunkel"合作过的演员姓名。这些SQL查询...
【一】Sqlzoo 练习 1-3 部分答案
在SQL语句中,创建计算字段,可以将其命名为新字段,使用引号包含字段名时如有空格需使用单引号。展示法国、德国、意大利的名称及人口数据。显示GDP至少达到万亿级别的国家人均GDP,并四舍五入到最接近的1000。计算并展示GDP达到万亿级别国家的人均GDP,四舍五入到最接近的1000。ROUND函数用于四舍五入,格...
SQLZOO练习题易错题汇总
在SQLZOO网站上进行SQL练习时,遇到了一些易错的题目,为了后续复习,我将这些问题整理如下。你可以通过以下链接访问SQLZOO网站:SQLZOO网站链接 同时,所有题目答案也可以在GitHub上找到:GitHub答案链接 1. SELECT基本练习从world表中,找出首都与国家名匹配的记录:查询包含国家名字的首都。显示国家名字及其扩展...
MySQL自学:SqlZoo答案全集(上)
MySQL自学过程中,SqlZoo是一个很好的实战平台。我已完成基础教程并整理了自己在解答过程中遇到并解决的题目答案,包括SQL语句和截图,希望能为自学MySQL的朋友提供参考。以下是部分题目和答案的示例:1. 修改查询以显示德国的人口:sql SELECT population FROM world WHERE name = 'Germany';2. 展示瑞典、...
SQL复杂查询 及 sqlzoo练习
今天学习升级,复杂查询六大知识点以及sqlzoo练习:一,视图 视图是数据库表中运行SQL查询后,存储在临时表中的结果(断开连接后自动删除)。创建视图语句:create view [视图名称] (列名) as [select 查询语句];例:创建按性别汇总的视图,包括性别及人数。使用视图时,通过select语句在from子句中使用...
MySQL练习-sqlzoo
通过使用SELECT语句,可以查询诺贝尔奖的详细信息。例如,查找EUGENE O'NEILL获得的奖项。理解SQL特殊字符处理 在编写SQL语句时,遇到单引号时需要进行转义。例如,使用两个单引号在字符串中表示一个单引号。使用IN子句与ORDER BY 使用IN子句可以指定多个值,同时在ORDER BY子句中可以使用IN子句的结果进行排序...
SQL(Mac英语版本)-简单查询+sqlzoo练习题
1. 基本的查询语句 2. 确定查询条件 3. 注释及SQL语句注意事项 4. 运算符的使用 5. 字符串的模糊查询 6. sqlzoo练习题 1. 基本的查询语句 当新列名为中文时,需使用英文单引号 Sql编写规则:2. 确定查询条件 编写顺序与SQL执行顺序不同。3. 注释及SQL语句注意事项 4. 运算符 涉及空值的运算...
SQLZOO实践记录和总结
实践SQL语言的方式有很多,但鉴于初学者阶段,推荐从基础入手。SQLZOO平台是一个很好的选择,网址为sqlzoo.net,它提供了SQL学习教程和丰富的练习题。SQLZOO平台的特色包括全面覆盖SQL学习内容,不仅提供理论知识,还有大量实践练习题。通过实践题,可以将理论知识应用于具体场景,加深理解。在使用SQLZOO平台的...