DEV Community

Cover image for SQL ๐Ÿ“Š challenge_3 โš”๏ธ
Mahmoud EL-kariouny
Mahmoud EL-kariouny

Posted on

SQL ๐Ÿ“Š challenge_3 โš”๏ธ

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;

Enter fullscreen mode Exit fullscreen mode

Code Snapshot:

Image description

My Problem ๐Ÿ’ก Solving Repo: Link

Learn SQL ๐Ÿ“Š

SQL ๐Ÿ”ฅ Get Expertise in SQL with These Top Free Courses๐Ÿ’ฏ๐Ÿ†

๐ŸŽฅ

Connect with Me ๐Ÿ˜Š

๐Ÿ”— Links

linkedin

twitter

Top comments (0)