SQL Syntax - how to group by interval

发现原来用SQL也可以group by interval,实现了类似SciQL里的grid grouping,虽然粒度只是1维上的grid,即interval。


In postgres (where || is the string concatenation operator):


select (score/10)*10 || '-' || (score/10)*10+9 as scorerange, count(*)
from scores
group by score/10
order by 1

gives:


scorerange | count 

------------+-------
 0-9           |    11
 10-19      |    14
 20-29      |     3
 30-39      |     2

你可能感兴趣的:(sql,grouping,by,group,interval)