SQL Select for multiple where clause
Posted
by
Tony
on Stack Overflow
See other posts from Stack Overflow
or by Tony
Published on 2010-12-21T23:41:02Z
Indexed on
2010/12/21
23:54 UTC
Read the original article
Hit count: 191
sql
|sql-server
Hi,
I am trying to create SQL Select that returns counts of a certain field based on a field. So, here is what I am trying to do.
Select count(distinct id) as TotalCount, -- this will be the total of id
count(distinct id where type='A') as TotalA, -- this will be total when type='A'
count(distinct id where type='B') as TotalB -- This will be total when type = 'B'
from MyTable
Basically, TotalCount = TotalA + TotalB.
How can I achieve this in SQL Select Statement? Thanks.
© Stack Overflow or respective owner