看板 Database 關於我們 聯絡資訊
※ 引述《littlepigred (小豬鴻)》之銘言: : 資料庫名稱:MySQL : 資料庫版本: : 內容/問題描述: : 今天去面試遇到一題題目如下: : name subject score : ──────────── : aaa math 90 : aaa chem 75 : aaa eng 70 : bbb chem 85 : bbb math 95 : bbb eng 90 : ccc eng 65 : ccc chem 80 : ccc math 75 : 請用SQL語法選出至少2科分數高於85且沒有任何一科低於75的人 : 小弟新手 麻煩各為求解QQ select name from( select name ,count(case when score>84 then 1 else null end) as [Over85] ,count(case when score<75 then 1 else null end) as [Below75] from scoretb group by name) tmp where [Over85]>=2 and [Below75]=0 -- Sent from my Windows -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.34.194.8 ※ 文章網址: https://www.ptt.cc/bbs/Database/M.1457709503.A.735.html
rockchangnew: 我是用MSSQL,MySQL您要試試看 03/12 00:42
mrforget: select name from tab where score >= 85 and exists 03/12 01:31
mrforget: (select name from tab where score <=75) 03/12 01:32
mrforget: group by name having count(name)>=2; 03/12 01:32
mrforget: 我是用oracle 03/12 01:32
mrforget: <=75那邊有錯,應該是<75 03/12 01:33
littlepigred: 我是原po 謝謝各位的解答 考試只說用SQL語法 沒特 03/12 23:51
littlepigred: 別設限 03/12 23:51
littlepigred: 不過我用MYSQL 好像不能用exists執行 我再研究 不過 03/12 23:52
littlepigred: 概念我了解了 謝謝各位! 03/12 23:52