由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 怎么写这个query呢?
相关主题
请教怎么来log duration of a MYSQL procedure?我也问一个sql querry的问题
菜鸟请教一个关于oracle里日期的问题请帮我看看,什么地方错了?
菜鸟问题,急[Mysql] how to return NULL count in group by query (转载)
急问Access Query问题:怎样查询最后一个非空的数值,谢谢求教为什么同样的query得到不同的运行结果
how to write this querySQL求助:两个表各自求Count
请问个join的问题please help with this left join question
error of sql query in MS Access database (转载)这2个query哪个快点,为啥
问个SQL的问题Question about the err when export table
相关话题的讨论汇总
话题: duration话题: nvl话题: when话题: 15话题: query
进入Database版参与讨论
1 (共1页)
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
1 (共1页)
进入Database版参与讨论
相关主题
Question about the err when export tablehow to write this query
A sql question请问个join的问题
query estimation shows cost 900%?error of sql query in MS Access database (转载)
Oracle新手请教一个问题问个SQL的问题
请教怎么来log duration of a MYSQL procedure?我也问一个sql querry的问题
菜鸟请教一个关于oracle里日期的问题请帮我看看,什么地方错了?
菜鸟问题,急[Mysql] how to return NULL count in group by query (转载)
急问Access Query问题:怎样查询最后一个非空的数值,谢谢求教为什么同样的query得到不同的运行结果
相关话题的讨论汇总
话题: duration话题: nvl话题: when话题: 15话题: query