This month's discount Comprehensive Database Performance Health Check · Testimonials
SQLAuthority with Pinal Dave
Home
  • Consulting
    • Health Check
  • Free Videos
  • All Articles
    • AI
    • SQL Performance
    • SQL Tips and Tricks
    • Interview Questions and Answers
    • SQL Puzzle
    • SQL Video
    • SQLAuthority News
    • Personal
  • Books
  • Consulting
A smooth band of mist following the shape of a jagged mountain ridge

Moving Averages in T-SQL

September 18, 2011
Pinal Dave
SQL Tips and Tricks
Ranking Functions, SQL Function, SQL Scripts, SQL Server

Moving averages in T-SQL use ROWS BETWEEN for rolling windows, but date gaps and duplicate dates decide what the result actually means.

Read More
SQL SERVER - Ranking Functions - RANK( ), DENSE_RANK( ), and ROW_NUMBER( ) - Day 12 of 35

SQL SERVER – Ranking Functions – RANK( ), DENSE_RANK( ), and ROW_NUMBER( ) – Day 12 of 35

August 12, 2011
Pinal Dave
SQL Tips and Tricks
Joes 2 Pros, Ranking Functions, SQL Scripts, SQL Server

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.

Read More
Three ceramic bowls hold wooden sticks beside a loose pile on an ochre workbench.

Whole Unit Allocation: Keep a Proportional Split Exact

May 14, 2011
Pinal Dave
SQL Tips and Tricks
Mathematical Function, Ranking Functions, SQL Scripts, SQL Server

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.

Read More
A hand fits a brass hinge pin while matching spare pins lie on the bench.

Finding Duplicates Before Adding a Unique Constraint

July 27, 2009
Pinal Dave
SQL Tips and Tricks
Duplicate Records, Ranking Functions, SQL Constraint and Keys, SQL Group By, SQL NULL

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.

Read More
A hand lifts the last dark log from an old firewood bay into a canvas bag already holding dark logs and one pale log.

FIFO Inventory Costing in T-SQL: Matching Sales to Purchase Lots

April 1, 2009
Pinal Dave
SQL Tips and Tricks
Ranking Functions, SQL Joins, SQL Scripts, Temp Table

Which purchase lot paid for which sale? Two running totals and one join answer it, with no cursor and no loop.

Read More
Matching red flower pots at tied heights and a gap in one ranking rack.

RANK vs DENSE_RANK: Keep Poll Ties at the Cutoff

March 27, 2009
Pinal Dave
SQL Tips and Tricks
Ranking Functions, SQL Function, SQL Order By

RANK vs DENSE_RANK gives tied vote totals different cutoff behavior. Keep display ordering separate from the tie criterion and rank each poll independently.

Read More
A hand deals plain counters among three cups, each already holding one red counter.

Assigning Rows Round-Robin to Workers With ROW_NUMBER

February 19, 2009
Pinal Dave
SQL Tips and Tricks
Ranking Functions, SQL Scripts, Temp Table

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.

Read More
Previous 1 2 3 4 5 6 Next
  • Books
  • Testimonials
  • Privacy Policy

© 2006 – 2026 All rights reserved. pinal @ SQLAuthority.com