Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Top Articles Per Section SQL
00:00
5 left

Top Articles Per Section SQL

MediumSQL · PostgreSQL

Problem

Write a SQL query to find the top 3 articles by views within each section for each day.

Use the article metadata and daily article view records. Return only articles with recorded view data, rank ties by the lower article_id, and exclude articles ranked below third place.

Output

  1. One row per selected article, day, and section.
  2. Columns: view_date, section, article_id, title, total_views, and article_rank.
  3. Sort by view_date, section, and article_rank ascending.

Schema

articles
ColumnTypeDescription
article_idPKINTUnique CNN article identifier
sectionVARCHAR(100)CNN content section containing the article
titleVARCHAR(255)Article headline
article_views
ColumnTypeDescription
view_idPKINTUnique view summary record identifier
article_idINTReferenced CNN article
view_dateDATEDate associated with the view count
viewsINTNumber of article views recorded for the date
Tablesarticlesarticle_views
Interviewer

Your question is Top Articles Per Section SQL. 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.