看板 Database 關於我們 聯絡資訊
小弟最近在自修資料庫,看到一個題目 環境是vb.net +mssql 有個一個資料表,有10筆資料(成績) 現在想弄個區間 例如 0-9分 10-19分,想要統計分數在該範圍內的人數 請問能直接用sql query 解嗎? 目前是用陣列去接十筆資料,再自己寫function求出答案 --
godtomanne:alt+f4沒有用?9/10 00:18
alt:去你媽的      9/10 00:24
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)
mervynW:group by ... having ... 04/03 14:59
kofi0916:select t.range as [score range], count(*) as [number 04/03 15:47
kofi0916:of occurences] 04/03 15:48
kofi0916:from ( 04/03 15:48
kofi0916:select case 04/03 15:49
kofi0916:when score between 0 and 9 then ' 0- 9' 04/03 15:49
kofi0916:when score between 10 and 19 then '10-19' 04/03 15:50
kofi0916:else '20-99' end as range 04/03 15:50
kofi0916:from scores) t 04/03 15:51
kofi0916:group by t.range 04/03 15:51
coolan:感謝各位的指點 04/03 22:49