Using the NTH_VALUE Function in SQL
📖 Scenario: You work in a sales department and want to analyze sales data to find specific sales amounts for each salesperson.
🎯 Goal: Build a SQL query that uses the NTH_VALUE function to find the 2nd highest sale amount for each salesperson.
📋 What You'll Learn
Create a table called
sales with columns salesperson (text) and amount (integer).Insert the exact sales data provided.
Write a query that uses
NTH_VALUE(amount, 2) to find the 2nd highest sale per salesperson.Partition the data by
salesperson and order by amount descending.💡 Why This Matters
🌍 Real World
Sales teams often need to analyze specific ranked sales amounts per salesperson to understand performance beyond just the top sale.
💼 Career
Knowing how to use window functions like NTH_VALUE is valuable for data analysts and database developers working with complex data queries.
Progress0 / 4 steps