假设在Oracle中有一个名为DISTANCES的表,该表的浮动类型列名为distance。距离范围是[0,1000]。我想知道距离的分布,例如,在以下每个范围中有多少行:(0,10],(10,50],(50,100],(100,500],.. 。(5000,10000]。
如何建立这个SQL查询?
使用派生表将每个距离归入其组。然后GROUP BY
和count
:
select dist_group, count(*)
from
(
select case when distance between 0 and 10 then '(0, 10)'
when distance between 10 and 50 then '(10, 50)'
...
when distance between 5000 and 10000 then '(5000, 10000)' end as dist_group
from distances
)
group by dist_group
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7467 次 |
最近记录: |