sql 除以_刷完这些SQL练习题,简单查询就熟能生巧了
練習(xí)題:SQLZOO
表:(圖片未顯示全部列)
(1)SELECT basics:(簡(jiǎn)單查詢)
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子句顯示“法國(guó)”的人口。請(qǐng)注意,字符串(作為數(shù)據(jù)的文本片段)應(yīng)在“單引號(hào)”中;
修改例子,以顯示德國(guó)的人口
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允許我們檢查項(xiàng)目是否在列表中。該示例顯示了“巴西”,“俄羅斯”,“印度”和“中國(guó)”國(guó)家的名稱和人口。
顯示“瑞典”,“挪威”和“丹麥” 的名稱和人口。
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.
哪個(gè)國(guó)家不太小也不太大? BETWEEN允許范圍檢查(指定的范圍包括邊界值)。以下示例顯示了面積為250,000-300,000平方公里的國(guó)家。對(duì)其進(jìn)行修改以顯示該國(guó)家/地區(qū)以及200,000到250,000之間的國(guó)家/地區(qū)的面積。
select name,area from world where area between 200000 and 250000(2)SELECT from WORLD Tutorial(運(yùn)算符練習(xí))
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.
觀察運(yùn)行此SQL命令的結(jié)果,以顯示所有國(guó)家的名稱,大洲和人口。
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億的國(guó)家/地區(qū)的名稱。2億就是200000000,有八個(gè)零。
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億的國(guó)家名字和人均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)的國(guó)家名稱,并將人口除以100萬(wàn),以獲得數(shù)百萬(wàn)人口數(shù)。
select name,population/1000000 from world where continent='South America'⑤Show the name and population for France, Germany, Italy
查找法國(guó),德國(guó),意大利(France, Germany, Italy)的國(guó)家名稱和人口
select name,population from world where name in ('France','Germany','Italy')⑥Show the countries which have a name that includes the word 'United'
查找國(guó)家名稱中包含“United”的國(guó)家
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.
兩種方式為大:大國(guó)是指一個(gè)國(guó)家面積超過(guò)300萬(wàn)平方公里,或者人口超過(guò)2.5億。
找出大國(guó)的名稱,人口和面積。
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.
找出符合下面條件的國(guó)家名稱,人口和面積。
條件:人口(大于250000000)或者面積(大于3000000)大的國(guó)家,排除同時(shí)面積大而且人口大的國(guó)家。
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%'來(lái)找出以 B 為開(kāi)首的國(guó)家。
%是任意字符串。
找出以 Y 字母開(kāi)頭的國(guó)家名稱。
select name from world where name like ‘Y%’②找出以 Y 字母結(jié)尾的國(guó)家名稱。
select name from world where name like ‘%Y’③“Luxembourg盧森堡”中有一個(gè)x字母,還有一個(gè)國(guó)家的名字中有x。列出這兩個(gè)國(guó)家。
找出所有國(guó)家名字中包括字母x。
select name from world where name like ‘%x%’④“Iceland 冰島”和“Switzerland 瑞士”的名字都是以”land”作結(jié)束的。還有其他嗎?
找出所有國(guó)家,其名字以 land 作結(jié)尾。
select name from world where name like ‘%land’⑤“Columbia 哥倫比亞”是以 C 作開(kāi)始,ia 作結(jié)尾的。還有兩個(gè)國(guó)家相同。
找出所有國(guó)家,其名字以 C 開(kāi)始,ia 結(jié)尾。
select name from world where name like ‘C%ia’⑥“Greece 希臘”中有雙 e 字。哪個(gè)國(guó)家有雙 o 字呢?
找出所有國(guó)家,其名字包括字母oo。
select name from world where name like ‘%oo%’⑦“Bahamas 巴哈馬”中有三個(gè) a,還有嗎?
找出所有國(guó)家,其名字包括三個(gè)或以上的a。
select name from world where name like ‘%a%a%a%’⑧“India 印度”和”Angola 安哥拉”的第二個(gè)字母都是 n。
你可以用底線符_當(dāng)作單一個(gè)字母的字串符。
找出所有國(guó)家,其名字以t作第二個(gè)字母。
select name from world where name like ‘_t%’ order by name⑨“Lesotho 賴索托”和”Moldova 摩爾多瓦”都有兩個(gè)字母 o,被另外兩個(gè)字母相隔著。
找出所有國(guó)家,其名字都有兩個(gè)字母o,被另外兩個(gè)字母相隔著。
select name from world where name like ‘%o__o%’⑩“Cuba古巴”和”Togo 多哥”都是 4 個(gè)字母。
找出所有國(guó)家,其名字都是 4 個(gè)字母的。
select name from world where name like '____'⑩①“Luxembourg 盧森堡”的首都 capital 都同樣叫“Luxembourg”。
查找所有國(guó)家的名字,其首都和國(guó)家名字是相同的。
select name from world where name=capital總結(jié)
以上是生活随笔為你收集整理的sql 除以_刷完这些SQL练习题,简单查询就熟能生巧了的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: java二维数组遍历排序,实现二维数组的
- 下一篇: java oracle数据库连接代码,j