January 3, 2007 at 9:46 am
Is it possible to use the count(*) statement more than once such as:
SELECT members, count(*) AS memberCnt, count(*) AS nonMemberCnt
January 3, 2007 at 11:38 am
Yes, use the column name instead of the *
January 3, 2007 at 12:59 pm
Yes, but why? Both of those will give the same value because you are counting all rows (COUNT(*)) both times.
And also, what are you trying to do?
Providing the table structure, sample data, and what results you want will help us come up with a solution.
-SQLBill
January 3, 2007 at 1:17 pm
soemthing like this is probably what you want: you want to use a case statement to determine how a row gets counted
SELECT SUM(CASE WHEN DUES > 0 THEN 1 ELSE 0 END) AS MEMBERCOUNT,
SUM(CASE WHEN DUES > 0 THEN 0 ELSE 1 END) AS NONMEMBERCOUNT
FROM SOMETABLE
Lowell
January 3, 2007 at 4:20 pm
It must be rather something like this:
SELECT count(P.ID) as Persons,
count(M.ID) as Members,
count(P.ID) - count(M.ID) as NonMembers
FROM dbo.Person P
LEFT JOIN dbo.Membership M ON M.PersonID = P.ID
_____________
Code for TallyGenerator
January 3, 2007 at 6:50 pm
Thanks to all who have responded!
I have used chosen to use Lowell's suggestion and it was what I was looking for. What I needed was a way to count up different levels of memberships such as a member having a full support (home page, pictures, the whole encillada), a member having partial support (no home page, but has pictures for example) and then there are other members with lesser benefits and lastly persons with no membership at all and is using free services. I needed that info so that I can display results accordingly.
Again, thanks to you all!
Dan
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply