查询电话记录

发布于 2025-01-12 18:42:42 字数 1453 浏览 6 评论 0原文

我想使用 SQL 来分析我拥有的这个通话数据。我想回答的主要问题是:如果呼叫者拨打一个号码并且第一次没有得到响应,some_factor(布尔列)的值是否会影响呼叫者得到响应的概率稍后重拨同一号码时有何反应?

以下是该表中的列:

| id | phone_number | callee_name | caller_id | call_duration | some_factor | created_at          |
|----|--------------|-------------|-----------|---------------|-------------|---------------------|
| 1  | 123-456-7890 | John Smith  | 42        |               | t           | 2022-03-07 09:40:40 |

这是我经过一番思考后得出的结果,但我对 SQL 查询相对缺乏经验。如果它们有效,我可以查看查询 1 的计数与查询 2 的计数的比率,然后重做 some_factor 为 false 的查询。

-- 1. successful retried calls: the callee picked up
SELECT COUNT(*)
FROM phone_calls
WHERE phone_number IN (
    SELECT phone_number
    FROM phone_calls
    WHERE call_duration IS NULL
    AND some_factor
)
AND call_duration IS NOT NULL

-- 2. unsuccessful retried calls: the callee did not pick up
SELECT COUNT(*)
FROM phone_calls
WHERE phone_number IN (
    SELECT phone_number
    FROM phone_calls
    WHERE call_duration IS NULL
    AND some_factor
)
AND call_duration IS NULL

-- then, do math with the results of these queries to get success rate when some_factor is true
-- then, redo but with AND NOT some_factor to get success rate when some_factor is false

但是,我意识到 2 正在将子查询中的条目计入总计数中。我希望 COUNT 不包括有人第一次拨打电话(如果他们没有接听)的时间。也许如果我可以排除带有与子查询中的条目相对应的 id 的条目,那就可以了。但我不知道该怎么做。我错过了什么吗?

I want to use SQL to analyze this call data I have. The main question I want to answer is: If a caller dials a number and doesn't get a response the first time, does the value of some_factor (boolean column) impact the probability of the caller getting a response when redialing the same number later?

Here are the columns in this table:

| id | phone_number | callee_name | caller_id | call_duration | some_factor | created_at          |
|----|--------------|-------------|-----------|---------------|-------------|---------------------|
| 1  | 123-456-7890 | John Smith  | 42        |               | t           | 2022-03-07 09:40:40 |

Here was what I arrived at after some thinking, but I'm relatively inexperienced with SQL queries. If they worked, I could look at the ratio of the count from query 1 compared to the count from query 2, and then redo the queries where some_factor is false.

-- 1. successful retried calls: the callee picked up
SELECT COUNT(*)
FROM phone_calls
WHERE phone_number IN (
    SELECT phone_number
    FROM phone_calls
    WHERE call_duration IS NULL
    AND some_factor
)
AND call_duration IS NOT NULL

-- 2. unsuccessful retried calls: the callee did not pick up
SELECT COUNT(*)
FROM phone_calls
WHERE phone_number IN (
    SELECT phone_number
    FROM phone_calls
    WHERE call_duration IS NULL
    AND some_factor
)
AND call_duration IS NULL

-- then, do math with the results of these queries to get success rate when some_factor is true
-- then, redo but with AND NOT some_factor to get success rate when some_factor is false

But, I realized that 2 is counting entries from the subquery in the total count. I want the COUNT to not include the first time that someone called a number, if they did not pick up. Maybe if I can exclude entries with an id that corresponds to entries from the subquery, that will work. But I can't figure out how to do that. Am I missing something?

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

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

发布评论

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

评论(1

花开半夏魅人心 2025-01-19 18:42:42

据我了解,在第二个查询中,您对子查询本身返回的结果不感兴趣。因此,计数结果会大于子查询返回的不同电话号码的数量。您只需减去该数字:

SELECT COUNT(*) - COUNT(DISTINCT phone_number)
FROM phone_calls
WHERE phone_number IN (
    SELECT phone_number
    FROM phone_calls
    WHERE call_duration IS NULL
    AND some_factor
)
AND call_duration IS NULL

As I understand in the second query you're not interested in the results returned by the subquery itself. So the count is as a result larger by the amount of distinct phone numbers returned by the subquery. You only need to subtract that number:

SELECT COUNT(*) - COUNT(DISTINCT phone_number)
FROM phone_calls
WHERE phone_number IN (
    SELECT phone_number
    FROM phone_calls
    WHERE call_duration IS NULL
    AND some_factor
)
AND call_duration IS NULL
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文