Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL: Most Clicked Ad
00:00
5 left

SQL: Most Clicked Ad

EasySQL · PostgreSQL

Problem

Identify the ad with the most clicks.

Asked in the Technical SQL round stage. Conceptually similar SQL problem reflecting what was asked in the interview.

Write a SQL query to return the ad or ads with the highest total number of clicks.

Output

  1. One row per ad that ties for the highest click total
  2. Columns: ad_id, ad_name, total_clicks
  3. Include only ads with at least one click
  4. Sort by total_clicks descending, then ad_id ascending

Schema

ads
ColumnTypeDescription
ad_idPKINTUnique identifier for the ad
ad_nameVARCHAR(255)Human-readable ad name
campaign_nameVARCHAR(255)Campaign the ad belongs to
is_activeBOOLEANWhether the ad is currently active
ad_clicks
ColumnTypeDescription
click_idPKINTUnique identifier for the click event
ad_idINTAd that received the click
clicked_atTIMESTAMPTimestamp when the click occurred
device_typeVARCHAR(50)Device used for the click
Tablesadsad_clicks
Interviewer

Your question is SQL: Most Clicked Ad. Start with the requirements and the two tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.