mysql 存储过程查询条数_mysql存储过程,查询多个重复的数据数据出现次数

匿名用户

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点的不要

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值