sql 除以_刷完这些SQL练习题,简单查询就熟能生巧了
練習題:SQLZOO
表:(圖片未顯示全部列)
(1)SELECT basics:(簡單查詢)
SELECT basics/zh?sqlzoo.net①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
該示例使用WHERE子句顯示“法國”的人口。請注意,字符串(作為數據的文本片段)應在“單引號”中;
修改例子,以顯示德國的人口
select population from world where name='Germany'②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 'Brazil', 'Russia', 'India' and 'China'.
Show the name and the population for 'Sweden', 'Norway' and 'Denmark'.
檢查列表單詞IN允許我們檢查項目是否在列表中。該示例顯示了“巴西”,“俄羅斯”,“印度”和“中國”國家的名稱和人口。
顯示“瑞典”,“挪威”和“丹麥” 的名稱和人口。
select name,population from world where name in ('Sweden','Norway','Denmark')③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.
哪個國家不太小也不太大? BETWEEN允許范圍檢查(指定的范圍包括邊界值)。以下示例顯示了面積為250,000-300,000平方公里的國家。對其進行修改以顯示該國家/地區以及200,000到250,000之間的國家/地區的面積。
select name,area from world where area between 200000 and 250000(2)SELECT from WORLD Tutorial(運算符練習)
SQLZOO:SELECT from WORLD Tutorial/zh?sqlzoo.net①Observe the result of running this SQL command to show the name, continent and population of all countries.
觀察運行此SQL命令的結果,以顯示所有國家的名稱,大洲和人口。
select name,continent,population from world②Show the name for the countries that have a population of at least 200 million. 200 million is 200000000, there are eight zeros.
顯示人口至少為2億的國家/地區的名稱。2億就是200000000,有八個零。
select name from world where population>=200000000③Give the name and the per capita GDP for those countries with a population of at least 200 million.
per capita GDP is the GDP divided by the population GDP/population
找出人口至少為2億的國家名字和人均GDP。人均GDP是GDP除以人口GDP /人口
select name,GDP/population as per capita GDP from world where population>=200000000④Show the name and population in millions for the countries of the continent 'South America'. Divide the population by 1000000 to get population in millions.
查找屬于南美洲(South America)的國家名稱,并將人口除以100萬,以獲得數百萬人口數。
select name,population/1000000 from world where continent='South America'⑤Show the name and population for France, Germany, Italy
查找法國,德國,意大利(France, Germany, Italy)的國家名稱和人口
select name,population from world where name in ('France','Germany','Italy')⑥Show the countries which have a name that includes the word 'United'
查找國家名稱中包含“United”的國家
select name from world where name like ‘%United%’⑦Two ways to be big: A country is big 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.
兩種方式為大:大國是指一個國家面積超過300萬平方公里,或者人口超過2.5億。
找出大國的名稱,人口和面積。
select name,population,area from world where area>3000000 or population>250000000⑧Exclusive OR (XOR). Show the countries that are big by area (more than 3 million) or big by population (more than 250 million) but not both. Show name, population and area.
找出符合下面條件的國家名稱,人口和面積。
條件:人口(大于250000000)或者面積(大于3000000)大的國家,排除同時面積大而且人口大的國家。
select name,population,area from world where (area>3000000 and population<=250000000) or (area<=3000000 and population>250000000)(3)SELECT names/zh(字符串模糊查詢)
SELECT names/zh - SQLZOO?sqlzoo.net①你可以用WHERE name LIKE 'B%'來找出以 B 為開首的國家。
%是任意字符串。
找出以 Y 字母開頭的國家名稱。
select name from world where name like ‘Y%’②找出以 Y 字母結尾的國家名稱。
select name from world where name like ‘%Y’③“Luxembourg盧森堡”中有一個x字母,還有一個國家的名字中有x。列出這兩個國家。
找出所有國家名字中包括字母x。
select name from world where name like ‘%x%’④“Iceland 冰島”和“Switzerland 瑞士”的名字都是以”land”作結束的。還有其他嗎?
找出所有國家,其名字以 land 作結尾。
select name from world where name like ‘%land’⑤“Columbia 哥倫比亞”是以 C 作開始,ia 作結尾的。還有兩個國家相同。
找出所有國家,其名字以 C 開始,ia 結尾。
select name from world where name like ‘C%ia’⑥“Greece 希臘”中有雙 e 字。哪個國家有雙 o 字呢?
找出所有國家,其名字包括字母oo。
select name from world where name like ‘%oo%’⑦“Bahamas 巴哈馬”中有三個 a,還有嗎?
找出所有國家,其名字包括三個或以上的a。
select name from world where name like ‘%a%a%a%’⑧“India 印度”和”Angola 安哥拉”的第二個字母都是 n。
你可以用底線符_當作單一個字母的字串符。
找出所有國家,其名字以t作第二個字母。
select name from world where name like ‘_t%’ order by name⑨“Lesotho 賴索托”和”Moldova 摩爾多瓦”都有兩個字母 o,被另外兩個字母相隔著。
找出所有國家,其名字都有兩個字母o,被另外兩個字母相隔著。
select name from world where name like ‘%o__o%’⑩“Cuba古巴”和”Togo 多哥”都是 4 個字母。
找出所有國家,其名字都是 4 個字母的。
select name from world where name like '____'⑩①“Luxembourg 盧森堡”的首都 capital 都同樣叫“Luxembourg”。
查找所有國家的名字,其首都和國家名字是相同的。
select name from world where name=capital總結
以上是生活随笔為你收集整理的sql 除以_刷完这些SQL练习题,简单查询就熟能生巧了的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java二维数组遍历排序,实现二维数组的
- 下一篇: MongoDB服务无法注册