mysql – Get the number without repetitions in one of the columns

Question:

We have a table manager – incoming number:

call_time | manager | aon
10:01 | user1 | 7972207
10:14 | user2 | 8581041
10:20 | user3 | 3642345
11:00 | user1 | 8089142
11:01 | user2 | 7972207
11:13 | user2 | 0297188
11:22 | user1 | 8089142
11:34 | user3 | 3642345
11:50 | user4 | 3642345

You need to get the number of unique calls by managers. But not every manager has unique calls, but unique calls in general. A unique call in this case is each unique aon . There is a timestamp in the table, so whoever received the call first is counted. For example, 3642345 has already accepted user3 , so there is no need to user4 it for user4 .

user1 2
user2 2
user3 1
user4 0

Answer:

The number of unique calls sorted by the time the number was first processed:

SELECT `manager`, COUNT(*) AS `calls` FROM (
    SELECT * FROM (
        SELECT `manager`, `aon` FROM `calls` ORDER BY `call_time` ASC
    ) t1
    GROUP BY `aon`
) t2
GROUP BY `manager`
Scroll to Top