January 28, 2008 at 10:47 am
CustIDFname LnameDOBEmail IDBalStateGender
1PaulSanders1/1/1948psanders@yahoo.com2000NYM
2DavidSato10/12/1985Sdavid@hotmail.com1000NJM
3PrinceDavidson11/1/1980dprince@gmail.com1100CTM
4RichardCooper1/10/1980rcooper@hotmail.com400NYM
5JudiMacpherson6/12/1986800VAF
6Diana Colon5/2/19601000VAF
7Roger Harris8/8/1961rharris@hotmail.com0NYM
8NancyNewton8/8/19401000NYF
9LillianThuram8/8/19650CTF
10Liliancole8/8/19401500NJF
11MathewRiley12/7/1981mriley@yahoo.com0NJM
and my question is to get the number of males in each state.
the format supposed to be like this.. i mean the result
ct ny nj
1 2 3
January 29, 2008 at 10:09 am
How about this one:
SELECT COUNT (*), State FROM T1 GROUP BY State, Sex HAVING Sex = 'M'
January 29, 2008 at 10:29 am
Having is used to filter on aggregated values. For a simple filter on a column value, rather use where.
SELECT COUNT (*), State FROM T1 WHERE Sex = 'M' GROUP BY State
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 29, 2008 at 10:43 am
Thanks dude it worked
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply