我需要帮助,我需要计算当前活动呼叫的数量。这是我的表:
+---------------------+---------+
| calldate | billsec |
+---------------------+---------+
| 2013-05-14 09:40:30 | 29 |
| 2013-05-14 09:40:31 | 24 |
| 2013-05-14 09:40:31 | 30 |
| 2013-05-14 09:40:33 | 20 |
| 2013-05-14 09:40:34 | 21 |
| 2013-05-14 09:40:35 | 30 |
| 2013-05-14 09:40:36 | 30 |
| 2013-05-14 09:40:37 | 30 |
| 2013-05-14 09:40:37 | 25 |
| 2013-05-14 09:40:39 | 22 |
| 2013-05-14 09:40:39 | 19 |
| 2013-05-14 09:40:40 | 22 |
| 2013-05-14 09:40:41 | 22 |
例如,如果我想计算'2013-05-14 09:40:34'中的活动呼叫数,我应该得到5条记录,因为例如,第一行呼叫是在'2013-05之间-14 09:40:30'和'2013-05-14 09:40:59'(calldate + billsec)。
由于
答案 0 :(得分:2)
select count(*) from calls
where '2013-05-14 09:40:34' between
calldate and DATE_ADD(calldate,INTERVAL billsec SECOND)
<强>更新强>
为了查看每个calldate的金额,您可以使用子查询
select B.calldate
,(select count(*) from calls A
where B.calldate between
A.calldate and DATE_ADD(A.calldate,INTERVAL A.billsec SECOND)) numcalls
from calls B
group by B.calldate