SQL練習題(2)

SQL練習

題目均取自sqlzoo, 在此只寫下自己的答案糙麦。

4. SELECT within SELECT

? ? 4.1?select name from world where population > (select population from world where name = 'Russia')

? ? 4.2 select name from world where (continent = 'Europe') and (gdp/population > (select gdp/population from world where name = 'United Kingdom'))

? ? 4.3?select name,continent from world where continent in (select continent from world where name = 'Argentina' or name ='Australia') order by name

? ? 4.4 select name,population from world where population > (select population from world where name= 'Canada') and population < (select population from world where name='Poland')

? ? 4.5?select name, concat(round(population/(select population from world where name = 'Germany')*100),'%' )from world where continent = 'Europe'

? ? 4.6?select name from world where gdp > all(select gdp from world where continent = 'Europe' and gdp is not null)

? ? 4.7? select continent,name,area from world where area in (select max(area) from world group by continent )

? ? 4.8?select continent, name from world x where name = (select name from world y where x.continent = y.continent order by name limit 1)

? ? 4.9?select name, continent, population from world x where 25000000>=all(select population from world y where x.continent = y.continent)

? ? 4.10?select name, continent from world x where population >= all(select population*3 from world y where x.continent = y.continent and x.name<>y.name)

5. SUM and COUNT

? ? 5.1?select sum(population) from world

? ? 5.2?select distinct continent from world

? ? 5.3?select sum(gdp) from world where continent = 'Africa'

? ? 5.4?select count(*) from world where area >=1000000

? ? 5.5 select sum(population) from world where name in ('Estonia', 'Latvia', 'Lithuania')

? ? 5.6 select continent,count(name) from world group by continent

? ? 5.7?select continent, count(name) from world where population > 10000000 group by continent

? ? 5.8?select continent from world group by continent having sum(population)>=100000000

6. The JOIN operation

? ? 6.1 select matchid, player from goal where teamid = 'GER'

? ? 6.2?select id, stadium, team1,team2 from game a join goal b on a.id = b.matchid where player = 'Lars Bender'

? ? 6.3?select player, teamid, stadium, mdate from game a join goal b on a.id = b.matchid where teamid = 'GER'

? ? 6.4?select team1, team2, player from game a join goal b on a.id = b.matchid where player like 'Mario%'

? ? 6.5?select player,teamid,coach,gtime from goal a join eteam b on a.teamid = b.id where gtime <=10

? ? 6.6?select mdate, teamname from game join eteam on team1=eteam.id where coach = 'Fernando Santos'

? ? 6.7?select player from goal join game on goal.matchid=game.id where stadium='National Stadium, Warsaw'

? ? 6.8?select distinct player from goal join game on matchid=id where (teamid=team2 and team1='GER') or (teamid=team1 and team2='GER')

? ? 6.9?select teamname,count(teamid) from goal join eteam on teamid=id group by teamname

? ? 6.10?select stadium, count(*) from game join goal on id=matchid group by stadium

? ? 6.11?select matchid, mdate, count(teamid) from game join goal on matchid=id where team1='POL' or team2='POL' group by matchid,mdate

? ? 6.12?select matchid, mdate,count(teamid) from game join goal on matchid=id where teamid='GER' group by matchid,mdate

? ? 6.13?select mdate,team1,sum(case when teamid=team1 then 1 else 0 end) score1,team2,sum(case when teamid=team2 then 1 else 0 end) score2 from game left join goal on matchid=id group by mdate,matchid,team1,team2

本章結(jié)束郊愧,下一章會講解一個機器學習入門項目:泰坦尼克號生存預測的實現(xiàn)儡循。

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末据途,一起剝皮案震驚了整個濱河市欣孤,隨后出現(xiàn)的幾起案子嫉沽,更是在濱河造成了極大的恐慌,老刑警劉巖械蹋,帶你破解...
    沈念sama閱讀 216,324評論 6 498
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件出皇,死亡現(xiàn)場離奇詭異,居然都是意外死亡哗戈,警方通過查閱死者的電腦和手機郊艘,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,356評論 3 392
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來唯咬,“玉大人暇仲,你說我怎么就攤上這事「笨剩” “怎么了奈附?”我有些...
    開封第一講書人閱讀 162,328評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長煮剧。 經(jīng)常有香客問我斥滤,道長,這世上最難降的妖魔是什么勉盅? 我笑而不...
    開封第一講書人閱讀 58,147評論 1 292
  • 正文 為了忘掉前任佑颇,我火速辦了婚禮,結(jié)果婚禮上草娜,老公的妹妹穿的比我還像新娘挑胸。我一直安慰自己,他們只是感情好宰闰,可當我...
    茶點故事閱讀 67,160評論 6 388
  • 文/花漫 我一把揭開白布茬贵。 她就那樣靜靜地躺著,像睡著了一般移袍。 火紅的嫁衣襯著肌膚如雪解藻。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,115評論 1 296
  • 那天葡盗,我揣著相機與錄音螟左,去河邊找鬼。 笑死觅够,一個胖子當著我的面吹牛胶背,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播喘先,決...
    沈念sama閱讀 40,025評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼钳吟,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了苹祟?” 一聲冷哼從身側(cè)響起砸抛,我...
    開封第一講書人閱讀 38,867評論 0 274
  • 序言:老撾萬榮一對情侶失蹤评雌,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后直焙,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體景东,經(jīng)...
    沈念sama閱讀 45,307評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,528評論 2 332
  • 正文 我和宋清朗相戀三年奔誓,在試婚紗的時候發(fā)現(xiàn)自己被綠了斤吐。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,688評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡厨喂,死狀恐怖和措,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情蜕煌,我是刑警寧澤派阱,帶...
    沈念sama閱讀 35,409評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站斜纪,受9級特大地震影響贫母,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜盒刚,卻給世界環(huán)境...
    茶點故事閱讀 41,001評論 3 325
  • 文/蒙蒙 一腺劣、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧因块,春花似錦橘原、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,657評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至吓懈,卻和暖如春歼冰,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背耻警。 一陣腳步聲響...
    開封第一講書人閱讀 32,811評論 1 268
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留甸怕,地道東北人甘穿。 一個月前我還...
    沈念sama閱讀 47,685評論 2 368
  • 正文 我出身青樓,卻偏偏與公主長得像梢杭,于是被迫代替她去往敵國和親温兼。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,573評論 2 353

推薦閱讀更多精彩內(nèi)容