组合两个时间间隔查询

发布于 2024-12-02 20:50:44 字数 782 浏览 0 评论 0原文

我有一个名为 Call_Data 的表,数据如下所示:

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

现在我想知道 Han_time > 的记录数1800 和 SL_Time>300

所以我编写了两个查询来执行此操作:

  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

是否有一种方法可以在一个查询中获取这两个值?

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 records 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

jJeQQOZ5 2024-12-09 20:50:44
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 
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 
深空失忆 2024-12-09 20:50:44

这不会有帮助吗:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文