Moving averages in T-SQL use ROWS BETWEEN for rolling windows, but date gaps and duplicate dates decide what the result actually means.
SQL SERVER – Ranking Functions – RANK( ), DENSE_RANK( ), and ROW_NUMBER( ) – Day 12 of 35
RANK( ), DENSE_RANK( ), and ROW_NUMBER( ) return the same results until your data has a tie. Day 12 shows how each ranking function handles tied values.
Whole Unit Allocation: Keep a Proportional Split Exact
Whole unit allocation keeps a fixed budget intact. I’d calculate base shares first, then distribute residual units using a stable tie rule. Check equal weights, a zero budget and zero-weight members.
Finding Duplicates Before Adding a Unique Constraint
A unique constraint fails on the first duplicate it meets and tells you about only one. Here is how to list them all and clean up safely.
FIFO Inventory Costing in T-SQL: Matching Sales to Purchase Lots
Which purchase lot paid for which sale? Two running totals and one join answer it, with no cursor and no loop.
RANK vs DENSE_RANK: Keep Poll Ties at the Cutoff
RANK vs DENSE_RANK gives tied vote totals different cutoff behavior. Keep display ordering separate from the tie criterion and rank each poll independently.
Assigning Rows Round-Robin to Workers With ROW_NUMBER
Number the tasks, number the workers, match them with a remainder. A fair queue in one query, and the two shortcuts that quietly break it.







