account_id from the Subscriptions table.LEFT JOIN to join the Streams table on account_id, including all subscriptions regardless of whether they have a corresponding stream.WHERE clause to filter for subscriptions that were active in 2021 (either started or ended in 2021).account_id using the GROUP BY clause.HAVING clause to ensure that for each account_id, there are no streams in 2021.account_ids that meet the criteria using COUNT(DISTINCT account_id).accounts_count.erDiagram
Subscriptions {
int account_id PK
date start_date
date end_date
}
Streams {
int session_id PK
int account_id FK
date stream_date
}
Subscriptions ||--o{ Streams : has