作者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