Sample Answer:
“I would first retrieve the previous month's sales using LAG(), then calculate the percentage change between the current month and previous month.”
SELECT Month,
Sales,
LAG(Sales) OVER (ORDER BY Month) AS Previous_Sales,
(Sales - LAG(Sales) OVER (ORDER BY Month))
* 100.0 /
LAG(Sales) OVER (ORDER BY Month) AS MoM_Growth
FROM Monthly_Sales;
“I would also handle cases where the previous month's value is zero or NULL to avoid incorrect calculations.”
🔟 What is the difference between DELETE, TRUNCATE, and DROP?
Sample Answer:
“DELETE removes selected rows from a table and can be used with a WHERE condition.
TRUNCATE removes all rows from a table while keeping the table structure.
DROP removes the entire table, including its structure and data.
So, the key difference is whether I'm removing specific records, all records, or the entire table itself.”
📌 Double Tap ❤️ For Part-4