de_notes

📚 LEAD

The LEAD() function is used in SQL to access data from the next row in the result set, without using a self-join.
It is helpful for comparing a row to the row that follows it.


🛠️ Basic Syntax

SELECT column1, 
       LEAD(column2, offset, default_value) OVER (PARTITION BY column3 ORDER BY column4) AS next_value
FROM table_name;

Example

SELECT employee_id, salary,
       LEAD(salary, 1) OVER (ORDER BY salary DESC) AS next_highest_salary
FROM employees;

Key Points

Additional Example

SELECT order_id, order_date,
       LEAD(order_date, 1) OVER (PARTITION BY customer_id ORDER BY order_date) AS next_order_date
FROM orders;

🎥 Video Notes


📝 Problem Description

Describe the problem, challenge, or topic discussed in a video related to SELECT FROM.
What concept was explained or what exercise was solved?


DataBase Given


💻 My SQL Code

-- Write your SQL code attempt or solution related to SQL COMMAND
SQL COMMAND

🧠 Solution Code / Explanation

SQL COMMAND

Explanation - Explain what you learned, any key takeaways, or how you solved the problem related to COMMAND._


⬅️ Previous: RANK Next ➡️ WITH STATEMENTS