Are you familiar with window functions? Can you explain any window function you have used in real time?
💡 Model Answer
Window functions operate on a set of rows related to the current row, called a window, and return a single value for each row. Common examples include ROW_NUMBER(), RANK(), DENSE_RANK(), NTILE(), and LAG()/LEAD(). A real‑world use case is calculating a running total of sales per customer:
SELECT customer_id,
order_date,
amount,
SUM(amount) OVER (PARTITION BY customer_id ORDER BY order_date
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS running_total
FROM orders;This query partitions the data by customer, orders each customer's orders chronologically, and sums amounts up to the current row, giving a cumulative total. Window functions are powerful for ranking, moving averages, and detecting gaps or duplicates without needing self‑joins or subqueries.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.
Get Assisting AI — Starts at ₹500