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
SQL for Top Marketing Channel
00:00
5 left

SQL for Top Marketing Channel

MediumSQL · PostgreSQL

Problem

Artech wants to identify its strongest marketing channels based on recent completed revenue. Write a SQL query to find the channel or channels with the highest completed revenue during the last fully completed calendar quarter.

Output

  1. One row per marketing channel tied for the highest revenue, with columns channel_name, total_revenue, and revenue_rank
  2. Include only completed transactions in the previous calendar quarter. Exclude refunded and other non-completed transactions, and treat missing revenue as contributing no revenue
  3. Include channels with no qualifying transactions when determining the top result
  4. Return every channel tied for first place, ordered alphabetically by channel_name

Schema

marketing_channels
ColumnTypeDescription
channel_idPKINTUnique marketing channel identifier
channel_nameVARCHAR(100)Artech marketing channel name
revenue_transactions
ColumnTypeDescription
transaction_idPKINTUnique revenue transaction identifier
channel_idINTMarketing channel associated with the transaction
transaction_dateDATEDate the transaction was recorded
revenueDECIMAL(12,2)Revenue attributed to the transaction
transaction_statusVARCHAR(20)Transaction state, such as completed or refunded
Tablesmarketing_channelsrevenue_transactions
Interviewer

Your question is SQL for Top Marketing Channel. 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.