作者tedcat (動靜:MSN暱稱為主)
看板Database
標題Re: [SQL ] 請問 103年軟體設計競賽題目
時間Sat Jul 18 11:19:18 2015
※ 引述《s900362123 (s900362123)》之銘言:
: 內容/問題描述:
: 請找出'groupB'參賽隊伍的答題中沒有任一小題為0分的隊伍,列出隊伍編號。顯示結果
: 採用隊伍編號由小而大排序顯示,且同一隊伍編號不重複顯示。
: 資料結構 :
: item_score
: groupname 可變長度字串(長度為10) –參賽組別, 分成’groupA’及’groupB’
: teamno 可變長度字串(長度為8) –隊伍編號
: pnum 整數(長度為2) – 題號, 預設值為0
: score 整數(長度為4) – 該題得分, 預設值為0
: 其中group、teamno 和pnum合起來為主鍵(primary key)。
比較直觀的想法是找出有=0的隊伍,然後把所有隊伍減掉剛剛得出的結果就是了
ms sql
select distinct teamno from item_score where groupname='groupB'
and teamno not in(
select distinct teamno from item_score where score=0 and groupname='groupB'
)
order by teamno
--
The Sword of Truth series
written- by
Terry GoodKind
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 115.43.104.85
※ 文章網址: https://www.ptt.cc/bbs/Database/M.1437189562.A.BFB.html
※ 編輯: tedcat (115.43.104.85), 07/18/2015 11:20:00
→ s900362123: 這樣可以 謝謝 但是因為teamno是varchar 所以 07/18 16:25
→ s900362123: order by 會從1開始排 沒辦法1.2.....這樣排 07/18 16:26
→ s900362123: 改成 ORDER BY convert(teamno , decimal) DESC 07/18 16:27
→ s900362123: 但是還是不行 07/18 16:27