gpt4 book ai didi

MySQl 累计计数与组

转载 作者:行者123 更新时间:2023-11-29 00:52:24 26 4
gpt4 key购买 nike

我正在尝试执行一个简单的查询,计算代理调用客户端的次数。

Call_ID  | Lead_id | Agent
1 | 1 | madison
2 | 1 | Kelly
3 | 2 | madison
4 | 1 | Sam

我需要添加另一个名为 call_attempt 的列,这对每个代理和领导都是唯一的

Call_ID  | Lead_id | Agent   | call attempt
1 | 1 | madison | 1
2 | 1 | Kelly | 2
3 | 2 | madison | 1
4 | 1 | Sam | 3

最佳答案

您可以通过表中先前出现的 lead_id 计算调用次数来计算排名,并使用如下查询更新到新的 call_attempt 字段:

update calls c
set call_attempt =
(select count(Lead_id) from calls c2
where c.Lead_id = c2.Lead_id and c2.Call_ID <= c.Call_ID);

这是一个演示:http://sqlize.com/fXn4p2cc5j

关于MySQl 累计计数与组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7840537/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com