Device Viewership Analysis
Beginner Mode
Objective
Write a SQL query to calculate total viewership for laptop devices and mobile devices (tablet plus phone combined).
Table Schema:
- viewership
| Column | Type | Description |
|---|---|---|
| user_id | INTEGER | ID of the user |
| device_type | VARCHAR | Type of device used (laptop, tablet, or phone) |
| view_time | DATETIME | Date and time when the view occurred |
Task Requirements:
- Calculate total views from laptop devices
- Calculate total views from mobile devices (tablet + phone combined)
- Return aggregated counts for both device categories
Output columns: laptop_views, mobile_views
Examples
Example 1:
Output:
Input:
| viewership | ||
|---|---|---|
| device_type | user_id | view_time |
| laptop | 101 | 2024-01-15 10:00:00 |
| tablet | 102 | 2024-01-16 11:00:00 |
| phone | 103 | 2024-01-17 12:00:00 |
| laptop | 104 | 2024-01-18 13:00:00 |
| tablet | 105 | 2024-01-19 14:00:00 |
| laptop_views | mobile_views |
|---|---|
| 2 | 3 |
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
Netflix