开发者

Combining two Time Interval queries

I have a table called Call_Data and the data looks like:

Arr_Date                   Interval    Han_Time   SL_Time  
2011-03-16 18:39:31.000    1830        1200       245
2011-03-16 20:06:03.000    2000        261        85
2011-03-31 00:35:42.000    0030        1900       400
2011-03-31 02:13:06.000    0200        2000       350

Now I want to know the number of recor开发者_运维问答ds that have Han_time > 1800 and SL_Time>300

So I wrote two queries to do that:

  Select Arr_Date, Interval,
    Count(*) AS Han_Time_1800
    From Call_Data
    where Han_Time>1800
    Group by Arr_Date,Interval
    Order by Arr_Date,Interval

Select Arr_Date, Interval,
Count(*) AS SL_Time_300
From Call_Data
where SL_Time>300
Group by Arr_Date,Interval
Order by Arr_Date,Interval

Is There a way that I could get both the values in one query?


select Arr_Date,
       Interval,
       sum(case when Han_Time > 1800 then 1 else 0 end) as Han_Time_1800,
       sum(case when SL_Time > 300 then 1 else 0 end) as SL_Time_300
from Call_Data
where Han_Time > 1800 or 
      SL_Time > 300
group by Arr_Date, Interval
order by Arr_Date, Interval 


Will this not help:

Select Arr_Date, Interval,
    Count(*) AS Han_Time_1800
    From Call_Data
    where Han_Time>1800
    and SL_Time>300
    Group by Arr_Date,Interval
    Order by Arr_Date,Interval
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜