DB2 ⭐ Featured
👁 0

Q: What is ROW_NUMBER()?

Answer:
ROW_NUMBER() assigns sequential numbers. ROW_NUMBER() OVER (ORDER BY col). Numbers restart per PARTITION BY group. Use for paging, deduplication (keep first), ranking. Result is numeric.
DB2
👁 0

Q: How to use window functions?

Answer:
ROW_NUMBER() OVER (PARTITION BY col ORDER BY col2). RANK, DENSE_RANK for rankings. SUM/AVG/COUNT OVER for running totals. PARTITION BY groups within result. ORDER BY within partition. Powerful analytics.
DB2
👁 0

Q: Explain RANK vs DENSE_RANK

Answer:
RANK() creates gaps for ties: 1,2,2,4. DENSE_RANK() no gaps: 1,2,2,3. ROW_NUMBER() no ties: 1,2,3,4. RANK useful for competition ranking. DENSE_RANK for level assignment. Choose based on need.