where嵌套select_Select子查询:Select Zoo
針對(duì)Select Zoo題庫平臺(tái),這次做的是select專題的練習(xí)SELECT within SELECT Tutorial和測試Nested SELECT Quiz。
一、SELECT within SELECT Tutorial:
SELECT within SELECT Tutorial?sqlzoo.net題目描述:
1、Bigger than Russia:
2、Richer than UK:
3、Neighbours of Argentina and Australia:
4、Between Canada and Poland:
5、Percentages of Germany:
6、Bigger than every country in Europe:
7、Largest in each continent:
8、First country of each continent:
9、Difficult Questions1:
10、Difficult Questions2:
上面是select子查詢部分所涉及的練習(xí)題,題目代碼均能正常運(yùn)行,獲得預(yù)期成功的笑臉結(jié)果。后面是對(duì)應(yīng)的測試題代碼,也是能正常運(yùn)行的代碼,可供大家參考。
二、Nested SELECT Quiz:
Nested SELECT Quiz?sqlzoo.net上面是練習(xí)題所涉及的表bbc
1. Select the code that shows the name, region and population of the smallest country in each region:
2.Select the code that shows the countries belonging to regions with all populations over 50000:
3.Select the code that shows the countries with a less than a third of the population of the countries around it:
4.Select the result that would be obtained from the following code:
5.Select the code that would show the countries with a greater GDP than any country in Africa (some countries may have NULL gdp values):
6.Select the code that shows the countries with population smaller than Russia but bigger than Denmark:
7.Select the result that would be obtained from the following code:
子查詢相關(guān)知識(shí)點(diǎn):
子查詢就是在一個(gè)select查詢語句中嵌套select查詢語句。
一般可以在from子句中直接下定義視圖的sql查詢語句,外面會(huì)用一個(gè)括號(hào)括起來。這是普通的多行子查詢,一般返回多行,也可以返回單行。
也可以結(jié)合使用in、any、all在where子句中直接書寫子查詢的sql查詢語句,這種子查詢是標(biāo)量子查詢。這種子查詢是單一數(shù)值,可以結(jié)合比較運(yùn)算符一起使用。
關(guān)聯(lián)子查詢時(shí)要使用兩個(gè)表名,第二個(gè)表名的ID數(shù)據(jù)要和第一個(gè)表名的ID數(shù)據(jù)進(jìn)行匹配。使用關(guān)聯(lián)條件進(jìn)行在每個(gè)組內(nèi)比較。
sql里還有5個(gè)重要的聚合函數(shù):
count(列名);求某列的行數(shù),如count(*)
sum(列名);對(duì)某列數(shù)據(jù)求和。它只能對(duì)數(shù)據(jù)類型的列計(jì)算。
avg(列名);求某列數(shù)據(jù)的平均值。它只能對(duì)數(shù)值類型的列計(jì)算。
max(列名);求某列數(shù)據(jù)的最大值
min(列名);求某列數(shù)據(jù)的最小值
總結(jié)
以上是生活随笔為你收集整理的where嵌套select_Select子查询:Select Zoo的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vb仿excel控件_如何通过INTOU
- 下一篇: 集群服务器分布式iis_集群,分布式,微