Leetcode Problem 1699. Number of Calls Between Two Persons

1699. Number of Calls Between Two Persons

Leetcode Solutions

Using LEAST and GREATEST Functions with GROUP BY

  1. Select the smaller of from_id and to_id using the LEAST function and alias it as person1.
  2. Select the larger of from_id and to_id using the GREATEST function and alias it as person2.
  3. Use COUNT(*) to calculate the number of calls between each pair and alias it as call_count.
  4. Use SUM(duration) to calculate the total duration of calls between each pair and alias it as total_duration.
  5. Group the results by person1 and person2 to ensure that each pair is counted only once.
erDiagram
    Calls {
        int from_id
        int to_id
        int duration
    }

Using CASE Statements with GROUP BY

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...