Diagnose join duplicates before using DISTINCT, verify order and payment totals, and choose aggregation or EXISTS for the required result.
MONTH, DATEPART and DATENAME: Getting Month Names and Numbers Right
Use DATENAME for month labels, compare MONTH and DATEPART, control language and culture, and group sales without combining different years.
Makers That Sell PCs but Not Laptops: HAVING With Conditional Counts
One WHERE clause cannot say ‘has a PC but no laptop’. Here are three queries that can, and the NULL trap.
Finding the Most Frequent Value per Group in T-SQL
Find the most frequent value in each group, choose a tie policy, and compare categorical modes with averages and numeric percentiles.
Cohort Retention Tables in T-SQL: From Raw Events to a Grid
Build a retention grid from raw orders with five rows you can check by eye. Includes the DISTINCT rule and why unfinished months show NULL.
Subtotals and Grand Totals With ROLLUP and GROUPING SETS
Build region, product, and grand totals with ROLLUP, CUBE, and GROUPING SETS, then label subtotal rows and compare plans.
Aggregate and Detail Columns in One Query: GROUP BY or OVER
Aggregate and detail columns in one query fail with Msg 8120 until you pick a way to keep the rows. This post compares GROUP BY, a scalar subquery and OVER on one small table, adds PARTITION BY and a share of the total, and then combines GROUP BY with OVER. Every result comes from SQL Server 2025.







