作者coolan (Cat Balloon)
看板Database
标题[SQL ] 资料库资料应用问题
时间Tue Apr 3 12:55:56 2012
小弟最近在自修资料库,看到一个题目
环境是vb.net +mssql
有个一个资料表,有10笔资料(成绩)
现在想弄个区间
例如 0-9分 10-19分,想要统计分数在该范围内的人数
请问能直接用sql query 解吗?
目前是用阵列去接十笔资料,再自己写function求出答案
--
1F:推 godtomanne:alt+f4没有用?9/10 00:18
2F:→ alt:去你妈的 9/10 00:24
3F:嘘 F4:你才没用 9/10 00:25
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 163.22.18.74
※ 编辑: coolan 来自: 163.22.18.74 (04/03 13:00)
※ 编辑: coolan 来自: 163.22.18.74 (04/03 13:07)
4F:→ mervynW:group by ... having ... 04/03 14:59
5F:→ kofi0916:select t.range as [score range], count(*) as [number 04/03 15:47
6F:→ kofi0916:of occurences] 04/03 15:48
7F:→ kofi0916:from ( 04/03 15:48
8F:→ kofi0916:select case 04/03 15:49
9F:→ kofi0916:when score between 0 and 9 then ' 0- 9' 04/03 15:49
10F:→ kofi0916:when score between 10 and 19 then '10-19' 04/03 15:50
11F:→ kofi0916:else '20-99' end as range 04/03 15:50
12F:→ kofi0916:from scores) t 04/03 15:51
13F:→ kofi0916:group by t.range 04/03 15:51
14F:→ coolan:感谢各位的指点 04/03 22:49