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
Gouache painting: a row of wooden crates of graduated widths along a barn wall, a chute pouring mangoes into the first and widest crate, one crate painted vermilion

Data Binning in T-SQL: Fixed Width, NTILE, CASE, DATE_BUCKET

October 13, 2023
Pinal Dave
SQL Tips and Tricks
Ranking Functions, SQL CASE, SQL DateTime, SQL Group By, SQL Scripts

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.

Read More
Count occurrences of a specific value in a column.

SQL SERVER – Count Occurrences of a Specific Value in a Column

June 12, 2023
Pinal Dave
SQL Interview Questions and Answers
SQL Group By, SQL Server

Here is the exact question – How to Count Occurrences of a Specific Value in a Column? Well, honestly, the answer is very simple.

Read More
A gardener walking a row of berry bushes with three small baskets on one strap, sorting berries in a single pass.

Conditional Aggregation: Several Counts in One Pass With CASE

June 24, 2021
Pinal Dave
SQL Tips and Tricks
PIVOT and UNPIVOT, SQL CASE, SQL Group By, SQL Scripts, SQL Server

Use conditional aggregation for several ticket counts, avoid COUNT with ELSE zero, and calculate percentages with an explicit denominator.

Read More
A knife block with five large knives, beside one small pot holding all the smaller utensils bunched together.

Top N Plus Others: Grouping the Rest Into One Row

December 3, 2020
Pinal Dave
SQL Tips and Tricks
Ranking Functions, SQL Group By, SQL Scripts, SQL Server, SQL Top

Create top N plus others summaries with deterministic category ranking, one remainder total, stable labels, and explicit display ordering.

Read More
Gouache painting of a seedling tray with most cells sprouted and three empty, with a vermilion watering can beside it

Count NULLs in a Column in SQL Server: Five Ways Compared

March 5, 2020
Pinal Dave
SQL Tips and Tricks
SQL Function, SQL Group By, SQL NULL, SQL Scripts

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.

Read More
Illustrated cover: Stream vs Hash Aggregate

SQL SERVER – Stream Aggregate and Hash Aggregate

February 17, 2020
Pinal Dave
SQL Performance
Execution Plan, MAXDOP, Parallel, Query Hint, SQL Group By, SQL Operator, SQL Server Management Studio

Recently during the on-demand consultation, I was asked a very interesting question about Stream Aggregate and Hash Aggregate.

Read More
Gouache painting of rows of pebbles arranged smallest to largest on a flat rock with one vermilion pebble

Does GROUP BY Sort Results? Only ORDER BY Guarantees It

October 23, 2019
Pinal Dave
SQL Tips and Tricks
Execution Plan, SQL Group By, SQL Order By, SQL Scripts

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.

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

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