Tom Cooper
3/15/2007 4:59:00 PM
Sorry, try
Select e.Gender, Count(*) As Number,
100 * (Cast(Count(*) As decimal(19,5))/ Max(t.TotalCount)) As 'Percent',
Avg(e.Salary) As AverageSalary
From employees e
Cross Join (Select Count(*) As TotalCount
From employees e1) As t
Group By e.Gender
Order By e.Gender
Tom
"rodchar" <rodchar@discussions.microsoft.com> wrote in message
news:01DA8DFB-BF21-47DD-B1D1-986E5ECFBCA6@microsoft.com...
> Hey Tom,
> I'm getting the following error:
> Column 't.TotalCount' is invalid in the select list because it is not
> contained in either an aggregate function or the GROUP BY clause.
>
> "Tom Cooper" wrote:
>
>> Answers inline
>> "rodchar" <rodchar@discussions.microsoft.com> wrote in message
>> news:596BBA47-8FE0-4966-AD7A-2ACB210A8892@microsoft.com...
>> > hey all,
>> > i have an employee table of the following:
>> > empID, Gender, Salary
>> >
>> > how do i get a count of male vs female?
>>
>> Select e.Gender, Count(*) As Number
>> From employees e
>> Group By e.Gender
>> Order By e.Gender
>>
>> >
>> > also, is it possible, in addition to the above, get the percentage of
>> > male
>> > and female, and avg of their salary all in one statment?
>>
>> Select e.Gender, Count(*) As Number,
>> 100 * (Count(*) / t.TotalCount) As Percent,
>> Avg(e.Salary) As AverageSalary
>> From employees e
>> Cross Join (Select Count(*) As TotalCount
>> From employees e1) As t
>> Group By e.Gender
>> Order By e.Gender
>>
>> >
>> > thanks,
>> > rodchar
>>
>> Tom
>>
>>
>>