In SQL, how can you “group by” in ranges?

前端 未结 15 2390
粉色の甜心
粉色の甜心 2020-11-22 15:38

Suppose I have a table with a numeric column (lets call it \"score\").

I\'d like to generate a table of counts, that shows how many times scores appeared in each ran

15条回答
  •  感情败类
    2020-11-22 16:35

    I would do this a little differently so that it scales without having to define every case:

    select t.range as [score range], count(*) as [number of occurences]
    from (
      select FLOOR(score/10) as range
      from scores) t
    group by t.range
    

    Not tested, but you get the idea...

提交回复
热议问题