[thelist] SQL query to create aging buckets

Paul Cowan evolt at funkwit.com
Wed Dec 17 16:32:28 CST 2003


> How does 'Count(*)' know what it's counting? What is the wildcard
> matching? BOL isn't offering an answer

The number of rows grouped, basically.

If you do:
	SELECT
		firstname, count(*)
	FROM
		mytable
	GROUP BY
		firstname

Then you're getting the number of rows in mytable for each firstname,
basically.
	Donald	5
	Mickey	3
etc.

This is subtly different from naming a specific column, which is the
way normal aggregate functions (SUM, MIN, etc) work:

	SELECT
		firstname, count(petname)
	FROM
		mytable
	GROUP BY
		firstname

Here, the COUNT will only return the number of rows for each firstname
where petname is not null -- so if, on some rows, Donald doesn't have
any pets, you might only get 3 as the result for him.

COUNT(*) is the only aggregate that has this behaviour, because saying
SUM(*) doesn't really make much sense.

Paul.


More information about the thelist mailing list