[dba-SQLServer] Count of records with zip

Stuart McLachlan stuart at lexacorp.com.pg
Tue Sep 21 17:11:53 CDT 2004


On 21 Sep 2004 at 14:35, John W. Colby wrote:

> I need what appears to me to be a crosstab, a COUNT of all records in a set
> of zip codes.  In other words, I have a table of zips (about 100).  I need a
> count of how many records in my nVLDB is in each zip code.  Can anyone point
> me in the right direction in SQL Server?
> 
Unless I'm misunderstanding you, that's not a crosstab. 

Off the top of my head, this would do it.

Select Distinct myTable.Zip, Count(*), from myTable Inner Join myZipTable 
on myTable.Zip = myZipTable.Zip Order by myTable.Zip



I
-- 
Stuart





More information about the dba-SQLServer mailing list