10. Find Nth Highest Revenue
Beginner Mode
Objective
Given a Sales table containing records of product sales, each with a unique identifier, product name, and revenue generated, write a SQL query to determine the third highest distinct revenue value from the sales data.
Additional information
- If there are fewer than three distinct revenue values, the query should return
null. - The result should be a single column named
revenue. - The
idcolumn is guaranteed to be unique for each record. - Use standard SQL syntax without relying on database-specific extensions.
Examples
Example 1:
Output:
Input:
| sales | ||
|---|---|---|
| id | product | revenue |
| 1 | Laptop | 2500 |
| 2 | Phone | 1800 |
| 3 | Tablet | 1200 |
| 4 | Desktop | 3000 |
| 5 | Camera | 1800 |
| 6 | Printer | 900 |
| revenue |
|---|
| 1800 |
Code Environment
Sign in or try as guest to run your code.
Essential
SQL 0/33
Spark 0/20
Snowflake 0/22
Python 0/24
Need more practice in this area? Explore more questions →
Dropbox
Revolut
Accenture
Adobe
Google
LinkedIn
Samsung
Datadog
Wix
Meta
OpenAI
Hulu
Uber
X
DoorDash
Anthropic
Amazon
ActivisionBlizzard
Vercel
Crypto.Com
Zscaler
DeutscheBank
Apple
GoDaddy
GitLab
BMW
PayPal
Snowflake
AMD
Twilio
Atlassian
JPMorgan
NVIDIA
IBM
Databricks
Coinbase
Cisco
Robinhood
Twitter
Microsoft
Palantir
Netflix
VMware
Cloudflare
Stripe
Lyft
Salesforce
GitHub
Bloomberg
Airbnb
Walmart
SAP
HashiCorp
Instacart
Mastercard
Intel
Visa
Tesla