Laptop Vs Mobile Viewership New York Times SQL Interview Question π₯
- Assume you're given the table on user viewership categorized by device type where the three types are laptop, tablet, and phone.
- Write a query that calculates the total viewership for laptops and mobile devices where mobile is defined as the sum of tablet and phone viewership.
- Output the total viewership for laptops as laptop_reviews and the total viewership for mobile devices as mobile_views.
β οΈNote:
- You have to visit the task URL to fully understand what the task needs if you want to add a solution or test your solution.
Task URL: Link
My Solution:
SELECT
SUM(CASE WHEN device_type = 'laptop' THEN 1 ELSE 0 END) AS laptop_views,
SUM(CASE WHEN device_type IN ('phone', 'tablet') THEN 1 ELSE 0 END) AS mobile_views
FROM viewership;
Code Snapshot:
My Problem π‘ Solving Repo: Link
Learn SQL π
SQL π₯ Get Expertise in SQL with These Top Free Coursesπ―π
π₯
Top comments (0)