Skip to primary content
Database Technical Prep

SQL Querying & Database Architecture Interview Questions

Crack SQL developer interviews: Window functions, CTEs, Clustered vs Non-clustered indexes, ACID properties, and query optimization.

Question 1

What are SQL Window Functions and how do they differ from GROUP BY?

Window functions perform calculations across a set of table rows related to the current row without collapsing the rows.

While a GROUP BY clause aggregates rows and collapses them into a single summary row per group, Window Functions (using the OVER clause with PARTITION BY and ORDER BY) compute aggregate or ranking values while preserving the original row-level identity. This makes them indispensable for running totals, moving averages, and finding the Nth highest value.

Database
-- Finding the top 2 highest scoring students in each course
WITH RankedStudents AS (
    SELECT 
        student_name,
        course_name,
        score,
        DENSE_RANK() OVER (PARTITION BY course_name ORDER BY score DESC) as rank_pos
    FROM student_evaluations
)
SELECT student_name, course_name, score
FROM RankedStudents
WHERE rank_pos <= 2;

Calculating month-over-month revenue growth where each transaction row needs to display both the current transaction amount and the running cumulative total for the year.

Interviewer Pro Tip: Know the exact differences between ROW_NUMBER(), RANK(), and DENSE_RANK() when ties occur in ordering.
Common Candidate Mistake: Attempting to filter window functions directly in the WHERE clause instead of wrapping them inside a CTE or subquery.

Related follow-up question: What is the difference between RANK() and DENSE_RANK()?

Mock Technical Interviews in Ghaziabad

Prepare for tier-1 company coding and system design rounds with face-to-face mock interview practice at C-60 R.K Tower, 3rd Floor, RDC, Ghaziabad.

Call 7503962162
Physical Training Center

Visit Our Ghaziabad Training Center

Join classroom batches, attend interactive lab sessions, code with mentors, and take advantage of our high-speed dev workstations.

Campus Address:
C-60 R.K Tower, 3rd Floor, RDC, Ghaziabad, Ghaziabad, Uttar Pradesh
Direct Counseling Helpline:
Call 7503962162
Get Google Maps Directions Call Now: 7503962162 Explore Ghaziabad Training Hub
Call 7503962162 Get Course Details