Complete the code to select the next salary value using LEAD function.
SELECT employee_id, salary, LEAD(salary) OVER (ORDER BY employee_id) AS next_salary FROM employees WHERE employee_id = [1];The LEAD function is used to access the next row's salary ordered by employee_id. The WHERE clause filters for employee_id = 5 (without quotes because employee_id is numeric).
Complete the code to get the next order date for each customer ordered by order_date.
SELECT customer_id, order_date, LEAD(order_date) OVER (PARTITION BY customer_id ORDER BY [1]) AS next_order_date FROM orders;The LEAD function needs to order rows by order_date within each customer partition to get the next order date.
Fix the error in the LEAD function usage to get the next product price ordered by product_id.
SELECT product_id, price, LEAD(price [1]) OVER (ORDER BY product_id) AS next_price FROM products;The LEAD function takes the offset as a second argument separated by a comma, so the correct syntax is LEAD(price, 1).
Fill both blanks to get the next and previous salaries for each employee ordered by employee_id.
SELECT employee_id, salary, LEAD(salary, [1]) OVER (ORDER BY employee_id) AS next_salary, LAG(salary, [2]) OVER (ORDER BY employee_id) AS previous_salary FROM employees;
Both LEAD and LAG functions use 1 as the offset to get the next and previous row values respectively.
Fill all three blanks to get the next salary, defaulting to 0 if none, ordered by employee_id.
SELECT employee_id, salary, LEAD(salary, [1], [2]) OVER (ORDER BY [3]) AS next_salary FROM employees;
The LEAD function uses 1 as offset, 0 as default value if no next row, and orders by employee_id.