Re: [SQL ] 請問 103年軟體設計競賽題目

看板Database作者 (可愛小孩子)時間8年前 (2015/07/19 16:10), 編輯推噓2(204)
留言6則, 4人參與, 最新討論串5/5 (看更多)
MSSQL: select cast(teamno as integer) num from item_score where groupname = 'groupB' group by teamno having min(score) != 0 order by num ※ 引述《s900362123 (s900362123)》之銘言: : 內容/問題描述: : 請找出'groupB'參賽隊伍的答題中沒有任一小題為0分的隊伍,列出隊伍編號。顯示結果 : 採用隊伍編號由小而大排序顯示,且同一隊伍編號不重複顯示。 : 資料結構 : : item_score : groupname 可變長度字串(長度為10) –參賽組別, 分成’groupA’及’groupB’ : teamno 可變長度字串(長度為8) –隊伍編號 : pnum 整數(長度為2) – 題號, 預設值為0 : score 整數(長度為4) – 該題得分, 預設值為0 : 其中group、teamno 和pnum合起來為主鍵(primary key)。 : 這是我寫的 : select a.groupname,a.teamno,a.pnum,a.score from : (select * from item_score where groupname="groupB" and score<>0)a, : (select * from item_score where groupname="groupB" and score=0 group by : teamno)b : where a.teamno <> b.teamno : group by teamno : 我先找出B所有的分數,再找出B 分數=0的資料 然後group by teamno : 條件所有的teamno不等於 B分數=0的teamno : 但是結果還是有=0的 teamno -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 210.61.233.210 ※ 文章網址: https://www.ptt.cc/bbs/Database/M.1437293426.A.836.html

07/19 21:22, , 1F
這個寫法比較好耶...
07/19 21:22, 1F

07/21 10:01, , 2F
前提是沒有負分呢XD
07/21 10:01, 2F

07/21 13:31, , 3F
哈哈,的確不能有「負分」XD
07/21 13:31, 3F

07/21 13:34, , 4F
不過加個 abs 就行了 →having min(abs(score)) != 0
07/21 13:34, 4F

07/21 17:23, , 5F
其實有負分也還是一樣阿~題目條件是沒有任一小題是0分
07/21 17:23, 5F

07/21 17:24, , 6F
負分一樣不是0分
07/21 17:24, 6F
文章代碼(AID): #1LgrjoWs (Database)
討論串 (同標題文章)
文章代碼(AID): #1LgrjoWs (Database)