Leetcode Problem 1809. Ad-Free Sessions

1809. Ad-Free Sessions

Leetcode Solutions

LEFT JOIN with Conditional Check for Null Ads

  • Perform a LEFT JOIN between Playback and Ads on two conditions:
    1. Playback.customer_id must be equal to Ads.customer_id.
    2. Ads.timestamp must be between Playback.start_time and Playback.end_time.
  • Select the session_id from the result of the LEFT JOIN.
  • Include a WHERE clause to filter out the sessions where ad_id is not NULL, as we are only interested in sessions without ads.
  • Return the resulting session_ids which represent sessions that had no ads shown.

erDiagram
    Playback {
        int session_id PK
        int customer_id
        int start_time
        int end_time
    }
    Ads {
        int ad_id PK
        int customer_id
        int timestamp
    }
    Playback ||--o{ Ads : has

Using NOT EXISTS with a Subquery

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...