Skip to content

1699. Number of Calls Between Two Persons 👍

1
2
3
4
5
6
7
SELECT
  LEAST(from_id, to_id) AS person1,
  GREATEST(from_id, to_id) AS person2,
  COUNT(*) AS call_count,
  SUM(duration) AS total_duration
FROM Calls
GROUP BY 1, 2;