Table Schema
Inspect
Table
| Column | Type |
|---|---|
| user_id | integer |
| product_name | varchar |
Find users who used more than 2 different products.
Table Schema
| Column | Type |
|---|---|
| user_id | integer |
| product_name | varchar |
Sample Data
| user_id | product_name |
|---|---|
| 101 | Teams |
| 101 | Outlook |
| 101 | Azure |
| 102 | Teams |
| 102 | Outlook |
| 103 | Azure |
| user_id |
|---|
| 101 |
SQL Editor
| user_id |
|---|
| 101 |
Hints
Solution
Solution is locked until you decide to reveal it. Try the editor first, then open this when you want the reference answer.
SELECT user_id FROM product_usage GROUP BY user_id HAVING COUNT(DISTINCT product_name) > 2;
Explanation
Read the expected output columns to determine the final grain.
Aggregate or rank the input rows to calculate the requested metric.
Filter, sort, and alias the final columns to match the output.
Related Questions