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
Highest-Grossing Products by Country
00:00
5 left

Highest-Grossing Products by Country

MediumSQL · PostgreSQL

Problem

Using CUST_ORDERS and CUSTOMERS, produce a report ranking the 2 highest-grossing products per country in 2015. Asked in the technical interview stage as SQL live coding.

Output

  1. One row per qualifying country and product, with columns country, product_name, total_revenue, and revenue_rank.
  2. Include products with ranks 1 or 2. Products tied on revenue share a rank and should all be included.
  3. Ignore rows with a NULL country or NULL order amount. Sort by country, rank ascending, total revenue descending, and product name ascending.

Schema

CUSTOMERS
ColumnTypeDescription
customer_idPKINTEGERUnique customer identifier
customer_nameVARCHAR(100)Customer name
countryVARCHAR(100)Customer country
CUST_ORDERS
ColumnTypeDescription
order_idPKINTEGERUnique order identifier
customer_idINTEGERCustomer who placed the order
product_nameVARCHAR(100)Product purchased
order_amountNUMERIC(12,2)Gross order amount
order_dateDATEOrder date
TablesCUST_ORDERSCUSTOMERS
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.