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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Optimize Queries in a Data Lake
00:00
5 left

Optimize Queries in a Data Lake

MediumSQL · PostgreSQL

Problem

Explain the strategies you would use to optimize query performance in a data lake.

Use the provided campaign and event tables for the SQL portion. Return only active campaigns with qualifying January 2026 event data.

Output

  1. One row per qualifying campaign with campaign_id, campaign_name, surface, total_impressions, total_clicks, and click_through_rate
  2. Include campaigns with positive January impressions only
  3. Order by total_impressions descending, then campaign_id ascending

Output details

  • Treat January 2026 as event dates from DATE '2026-01-01' inclusive through DATE '2026-02-01' exclusive.
  • Match campaigns whose status equals the literal active.
  • Treat NULL clicks as 0 when calculating total_clicks and click_through_rate.
  • Round click_through_rate to 4 decimal places.

Schema

mi_campaigns
ColumnTypeDescription
campaign_idPKINTUnique campaign identifier
campaign_nameVARCHAR(120)Campaign display name
surfaceVARCHAR(40)Movable Ink delivery surface
statusVARCHAR(20)Campaign lifecycle status
mi_event_facts
ColumnTypeDescription
event_idPKBIGINTUnique event fact identifier
campaign_idINTReferenced campaign identifier
event_dateDATEDate used for event partitioning
event_typeVARCHAR(30)Type of recorded engagement event
impressionsINTNumber of delivered impressions
clicksINTNumber of recorded clicks
Tablesmi_campaignsmi_event_facts
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the two tables are in the Question tab.

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.