Database Management
PostgreSQL
Subjective
Sep 25, 2025
What are PostgreSQL window functions and provide examples.
Detailed Explanation
Window functions perform calculations across a set of table rows related to the current row.
Common Functions:
• ROW_NUMBER(): Sequential numbering
• RANK(): Ranking with gaps
• LAG()/LEAD(): Access previous/next rows
• SUM() OVER: Running totals
Example:
SELECT name, salary,
ROW_NUMBER() OVER (ORDER BY salary DESC) as rank,
SUM(salary) OVER (ORDER BY salary) as running_total
FROM employees;Discussion (0)
No comments yet. Be the first to share your thoughts!
Share Your Thoughts