Blog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2025 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/Databases
Databasesmedium

What is a window function in SQL and a typical use case?

Tags
#sql#window-functions#row_number
Back to categoryPractice quiz

Answer

A window function computes a value over a “window” of rows related to the current row without collapsing rows like GROUP BY. Use cases: ranking (ROW_NUMBER), running totals, “top N per group”.

SELECT user_id,
       amount,
       ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY created_at DESC) AS rn
FROM payments;

Related questions

Databases
Why can `LIKE '%term%'` be slow and what are common alternatives?
#sql#like#indexes
Databases
SQL NULL: why is `col = NULL` not true and what should you use?
#sql#null#three-valued-logic
Databases
Why is `SELECT *` risky in production queries?
#sql#best-practices#performance
Databases
GROUP BY vs HAVING — what’s the difference?
#sql#group-by#having
Databases
INNER JOIN vs LEFT JOIN — what’s the difference?
#sql#join#inner-join
Databases
SQL vs NoSQL?
#sql#nosql#comparison