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

前端 未结 15 2416
粉色の甜心
粉色の甜心 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:22

    Try

    SELECT (str(range) + "-" + str(range + 9) ) AS [Score range], COUNT(score) AS [number of occurances]
    FROM (SELECT  score,  int(score / 10 ) * 10  AS range  FROM scoredata )  
    GROUP BY range;
    

提交回复
热议问题