匿名用户
1级
2015-01-17 回答
update B
set b = (select count(*)
from A
group by a
having count(*) > 1),
c = (select count(*)
from A
group by a
having count(*) = 1)
追问:
插入B表中,不是更新
追答:
insert into B(b, c)
select count(*), null
from A
group by a
having count(*) > 1
union all
select null, count(*)
from A
group by a
having count(*) = 1
追问:
比如客服接电话
如果表A有:客服id,呼叫时间,电话号码
B表3列分别放:客服id;2小时内重复呼叫量;2小时内未重复呼入的量
该如何写存储过程,将A中符合B中条件的数据,放到B中。
这是另一个问题,追加20分
追问:
表A:员工id,呼叫时间,呼叫号码
表B:员工id,2小时重复呼叫数量,2小时不重复呼叫数量
现在要将A表中的数据按照“同一个号码2小时是否重复呼叫”放到B表中。咋做?
追答:
现在要将A表中的数据按照“同一个号码2小时是否重复呼叫”放到B表中。咋做?
update B
set 2小时内重复呼叫量 = (select count(*)
from A
where B.客服id = A.客服id
and 呼叫时间 >= sysdate + 1/24 * 2
group by 电话号码
having count(*) > 1),
2小时内未重复呼入的量 = (select count(*)
from A
where B.客服id = A.客服id
and 呼叫时间 >= sysdate + 1/24 * 2
group by 电话号码
having count(*) = 1);
否重复呼叫 = (select case when count(*) > 1 then '有重复' else '没有重复' end
from A
where B.客服id = A.客服id
and 呼叫时间 >= sysdate + 1/24 * 2
group by 电话号码
having count(*) > 1);
追问:
and 呼叫时间 >= sysdate + 1/24 * 2 是什么意思??
追答:
and 呼叫时间 >= sysdate + 1/24 * 2
不好意思写错了,
应该是
and 呼叫时间 >= sysdate - 1/24 * 2
例如
呼叫时间0点 >= 当前是3点 - 2小时
0> 1 不符合的,也就是0点的不要