Data binning turns a column of numbers into a few groups you can count and chart. This post runs four T-SQL methods on the same orders on SQL Server 2025: fixed width, NTILE, CASE ranges and DATE_BUCKET. It shows what each method tells you and one trap with BETWEEN.
SQL SERVER – Count Occurrences of a Specific Value in a Column
Here is the exact question – How to Count Occurrences of a Specific Value in a Column? Well, honestly, the answer is very simple.
Conditional Aggregation: Several Counts in One Pass With CASE
Use conditional aggregation for several ticket counts, avoid COUNT with ELSE zero, and calculate percentages with an explicit denominator.
Top N Plus Others: Grouping the Rest Into One Row
Create top N plus others summaries with deterministic category ranking, one remainder total, stable labels, and explicit display ordering.
Count NULLs in a Column in SQL Server: Five Ways Compared
To count NULLs in a column, filter with IS NULL and count the rows, or subtract COUNT(column) from COUNT(*). This post tests five ways on 100,000 rows and compares their page reads. It also counts NULLs in several columns at once and shows the NULL group in GROUP BY.
SQL SERVER – Stream Aggregate and Hash Aggregate
Recently during the on-demand consultation, I was asked a very interesting question about Stream Aggregate and Hash Aggregate.
Does GROUP BY Sort Results? Only ORDER BY Guarantees It
Does GROUP BY sort the rows it returns? No: only ORDER BY guarantees an order. This post builds a small demo, shows one GROUP BY query returning two different orders, and reads the plans that explain why.







