Annual Pass Available: Save up to 70%

The Cleanest Way to Get Interview-Ready in SQL, Python, and R

Structured practice, realistic datasets, and focused execution loops to help you perform with clarity in technical interviews.

230+

Interview-style coding questions

23+

Company-focused question sets

4

Practice engines: Postgres, MySQL, Python, R

March 2026 Leaderboard

User Score
#1 Ranked user: Blake
Blake Gold
115 pts
#2 Ranked user: Sydney
Sydney Silver
66 pts
#3 Ranked user: Greg
Greg Bronze
60 pts
#4 Ranked user: Deeptarka
Deeptarka
56 pts
#5 Ranked user: 421
421
55 pts
#6 Ranked user: Juan Andrés
Juan Andrés
50 pts
#7 Ranked user: shweta
shweta
47 pts
#8 Ranked user: Michaela
Michaela
42 pts
#9 Ranked user: Marieke
Marieke
38 pts
#10 Ranked user: Margareta
Margareta
38 pts

Anonymous Playground

Try a Real Question Before You Sign Up

Run SQL, Python, or R directly on this page. You can practice this sample without logging in.

Question 94

Top 3 products vs. bottom 3 products

Instructions:

  • Write a query to return the top 3 and bottom 3 products in August 2021 ranked by sales.
  • sales = sum(unit_price_usd * qty) .
  • ordering of your results is not considered

Hint

  • Make sure you clarify with the interviewer on how to deal with ties

Table: orders

An eCommerce company's online order table.

  col_name    | col_type
--------------+-------------------
order_id      | bigint
product_id    | bigint
customer_id   | bigint
order_dt      | date
qty           | integer
unit_price_usd| float
channel       | varchar(20) -- mobile, desktop

Sample results

 product_id | category
------------+----------
   10000045 | top
   10000060 | top
   10000067 | top
   10000089 | bottom
   10000036 | bottom
   10000065 | bottom

Official solution

POSTGRES
WITH top AS(
	SELECT product_id, SUM(unit_price_usd * qty)
	FROM orders
        WHERE order_dt >= '2021-08-01'
        AND order_dt < '2021-09-01'
	GROUP BY product_id
	ORDER BY SUM(unit_price_usd * qty) DESC 
	LIMIT 3
), 
bottom AS (
	SELECT product_id, SUM(unit_price_usd * qty) 
	FROM orders
        WHERE order_dt >= '2021-08-01'
        AND order_dt < '2021-09-01'
	GROUP BY product_id
	ORDER BY SUM(unit_price_usd * qty) 
	LIMIT 3
)
SELECT top.product_id, 'top'  AS category
FROM top
UNION ALL
SELECT bottom.product_id, 'bottom' AS category
FROM bottom;
Explanation

This query is used to identify the top and bottom selling products based on their revenue generated during a specific time period. The time period in question is between August 1, 2021, and September 1, 2021.

The query first creates two temporary tables using common table expressions (CTEs) named "top" and "bottom". These tables contain the top 3 and bottom 3 products, respectively, based on their revenue generated during the specified time period.

The revenue generated for each product is calculated by multiplying the unit price of the product with the quantity sold. This calculation is done for each order within the specified time period.

The "top" and "bottom" tables are then combined using a UNION ALL operator to create a final result set that contains the product IDs and a category column that identifies whether the product is in the top or bottom category.

Overall, this query helps a data analyst to quickly identify the products that are performing well or poorly during a specific time period, which can be useful for making business decisions such as inventory management or product promotions.

Expected results

Expected results appear after you submit.

Learners on SQLPad target interviews at

Loading testimonials...

Value Calculator

Estimate Your ROI with SQLPad

Enter your current salary and compare potential compensation upside against your SQLPad plan investment.

Summary

SQLPad starts at only $79/mo

Estimated annual upside

$0/year

Estimated ROI

0%

This salary estimate is based on publicly available compensation data for data scientists at top U.S. tech firms. Outcomes vary by interview performance, location, and hiring urgency.

Data engineers and machine learning engineers often earn more, so ROI can be higher for engineering-focused roles.

Loading FAQ...

Ready to Begin

Practice Daily. Interview Better.

Use SQLPad consistently and turn interview prep into a structured system instead of a guessing game.