Leetcode Problem 1501. Countries You Can Safely Invest In

1501. Countries You Can Safely Invest In

Leetcode Solutions

Identifying Investment-worthy Countries Based on Call Duration

  1. Join the Person table with the Country table on the country code extracted from the phone_number column.
  2. Join the resulting table with the Calls table where the Person.id matches either Calls.caller_id or Calls.callee_id.
  3. Use the GROUP BY clause to group the results by country name.
  4. Calculate the average call duration for each country using the AVG function.
  5. Use a subquery to calculate the global average call duration from the Calls table.
  6. Use the HAVING clause to filter the results where the country's average call duration is greater than the global average.
  7. Select the country names that meet the criteria.
erDiagram
    Person {
        int id
        varchar name
        varchar phone_number
    }
    Country {
        varchar name
        varchar country_code
    }
    Calls {
        int caller_id
        int callee_id
        int duration
    }
    Person ||--o{ Calls : ""
    Country ||--o{ Person : ""

Comparing Country-Specific Call Durations Against Global Average

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...