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

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay