c***c 发帖数: 6234 | 1 我想把duration 分组,分为0-4,4-7,7-15,>15这么几组,看看每组共几个
能用一个query写出来吗。还是必须写4个?
select count(*)
from table1
group by duration
谢谢 | b*****e 发帖数: 364 | 2 select CASE
when duration between 0 and 4 then '0-4'
when duration between 5 and 7 then '5-7'
when duration between 8 and 15 then '8-15'
when duration>15 then '>15'
End as Range,
count(*)
from table1
group by
CASE
when duration between 0 and 4 then '0-4'
when duration between 5 and 7 then '5-7'
when duration between 8 and 15 then '8-15'
when duration>15 then '>15'
| c***c 发帖数: 6234 | 3 谢谢。google了pivot table
其实就是用case when then else end 语句。还是query不熟。最后我写成
select count(case when (nvl(t.resolved_time, nvl(t.close_time,sysdate))- t.open_time) <= 4 then t.id else null end) as "<4",
count(case when (nvl(t.resolved_time, nvl(t.close_time,sysdate))- t.open_time) >4 and (nvl(t.resolved_time, nvl(t.close_time,sysdate))- t.open_time) <7 then t.id else null end) as "4-7",
count(case when (nvl(t.resolved_time, nvl(t.close_time,sysdate))- t.open_time) >=7 and (nvl(t.resolved_time, nvl(t.c |
|