SQLZOO-SELECT from Nobel Tutorial

http://sqlzoo.net/wiki/SELECT_from_Nobel_Tutorial


1、selectyr,subject,winner

from nobel

where yr = 1950


2.、select winner

from nobel

where yr='1962' and subject='Literature'


說明:where語句中對表示條件的需要用單引號。


3、select yr,subject

from nobel

where winner='Albert Einstein'


4、select winner

from nobel

where subject= 'Peace'and yr>='2000'


5、selectyr,subject,winner

from nobel

where subject='Literature'and yr between1980 and 1989


6、selectyr,subject,winner

from nobel

where winner in ('TheodoreRoosevelt','Woodrow Wilson','Jimmy Carter','Barack Obama')


7、select winner

from nobel

where winner like 'John%'


8、selectyr,subject,winner

from nobel

where subject='Physics' and yr=1980

or (subject='Chemistry'and yr='1984')


或者


Select * from nobel

Where subject='Physics' and yr=1980

or (subject='Chemistry'and yr='1984')


9、select * fromnobel

where subject not in ('Chemistry','Medicine')and yr='1980'


10、select * fromnobel

where subject= 'Medicine' and yr<'1910'

or subject= 'Literature' and yr>='2004'


11、select * fromnobel

where winner='PETER GRüNBERG'


說明:元音字母“ü”輸入方法為“alt+0220”即可。


12、select * fromnobel

where winner='EUGENE O''NEILL'


說明:條件語句中的“EUGENE O'NEILL”因?yàn)楹袉我枺枧csql語句中的單引號區(qū)分,所以在本身名稱單詞中已經(jīng)包含的單引號使用兩個單引號,即為'EUGENE O''NEILL'



13、selectwinner,yr,subject from nobel

where winner like 'Sir%'

order by yr desc,winner desc


或者select winner,yr,subject from nobel

where winner like 'Sir%'

order by yr desc,winner


說明:原題中要求先顯示最新獲獎?wù)撸偻臧凑彰Q順序排序,則表示時間順序排序?yàn)榻敌颍从谩癲esc”,



14、原題:Show the 1984winners and subject ordered by subject and winner name; but list Chemistry andPhysics last.


Select winner,subject from nobel

WHERE YR='1984'

order by subjectin('Chemistry','Physics'),subject,WINNER


或者


SELECT winner, subject, subject IN('Physics','Chemistry')

?FROM nobel

?WHERE yr=1984

?ORDER BY subject,winner



說明:

使用ORDER

BY配合IN語句

原題要求按照項(xiàng)目subject和獲獎?wù)咝彰鹷inner排序,同時要求獲獎項(xiàng)目為Physics和Chemistry的排在最后。


Subject in()配合order

by 語句的意思是subject in(’Physics’,’Chemistry’)進(jìn)行判斷,如果屬于項(xiàng)目Physics或?qū)儆陧?xiàng)目Chemistry,則為真返回數(shù)值“1”,如果不屬于,則為假返回數(shù)值“0”,按照默認(rèn)的asc升序排序,則判斷為真返回數(shù)值為“1”的會排在最后,所以項(xiàng)目為Physics和Chemistry的自然就會排在最后。同時order by逗號后面的內(nèi)容“,subject,winner”意為 將剩下不屬于Physics和Chemistry的數(shù)據(jù)按照默認(rèn)升序排序asc;姓名也按照默認(rèn)升序排序asc。


參考資料:

MySQL

ORDER BY 排序 IF 及IN

https://blog.csdn.net/bestallen/article/details/53726192


????@?3?;#?6?

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

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

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,449評論 0 10
  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,921評論 0 23
  • 【一】 “擺渡人”這幾年勢頭一直很猛啊!似乎可以看到很多人朝擺渡人的船只擠來了。 2016近年末,由阿里影業(yè)、澤東...
    靈渠清韻閱讀 472評論 0 0
  • 在我們的工作或生活中總是會面臨很多的變化和不確定性。例如:公司組織結(jié)構(gòu)變化,團(tuán)隊(duì)成員變化,失去親人等等。面對變化,...
    李文艷Avivi閱讀 990評論 0 1
  • 1 微風(fēng)最近為一件事很困擾。 她屁股上的熒光不如以前亮了。 這放在以前不是什么特別大不了的事,畢竟她還是個非常年輕...
    puzzle圈兒閱讀 356評論 0 0