Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Top 10 Query

EasySQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL Top 10 Query. Start with the requirements and the one table on the right.

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.

Problem

Celebal Technologies needs the highest-value sales records for a Power BI dashboard. Write a PostgreSQL query that retrieves the top 10 individual sales from the sales table.

Requirements

  1. Return the sale ID, product name, sales amount, and sale date.
  2. Sort records by sales_amount from highest to lowest and return only 10 rows. Place NULL amounts after numeric values and use sale_id as a deterministic tie-breaker.

Schema

sales
ColumnTypeDescription
sale_idPKINTUnique sale identifier
product_nameVARCHAR(100)Name of the sold product
sales_amountNUMERIC(12,2)Monetary value of the sale
sale_dateDATEDate when the sale occurred
Tablessales
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results