Playback and Ads on two conditions:
Playback.customer_id must be equal to Ads.customer_id.Ads.timestamp must be between Playback.start_time and Playback.end_time.session_id from the result of the LEFT JOIN.ad_id is not NULL, as we are only interested in sessions without ads.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