作者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://webptt.com/cn.aspx?n=bbs/Database/M.1437189562.A.BFB.html
※ 编辑: tedcat (115.43.104.85), 07/18/2015 11:20:00
1F:→ s900362123: 这样可以 谢谢 但是因为teamno是varchar 所以 07/18 16:25
2F:→ s900362123: order by 会从1开始排 没办法1.2.....这样排 07/18 16:26
3F:→ s900362123: 改成 ORDER BY convert(teamno , decimal) DESC 07/18 16:27
4F:→ s900362123: 但是还是不行 07/18 16:27