Display the total of instances within a SQL table with condition

We are trying to know total instances in a column based on a value of another column.  For example, the column below is to migrate contracts.  We need to script and display that there are 4 contracts that will be migrated (this is because column2 = 'Migrate').

Column1  Columna2
contract1  Migrate 
contract2  NO
contract2  NO
contract2  Migrate
contract3  Migrate
contract4  No
contract5  Migrate
contract5  Migrate

Open in new window

rayluvsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tim_csCommented:
This should work.

SELECT COUNT(DISTINCT Column1)
FROM TestTable
WHERE
   Column2 = 'Migrate'

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Brian CroweDatabase AdministratorCommented:
Schema and expected output would be beneficial to get a complete answer.  Here's a guess based on what you did provide:

SELECT COUNT(DISTINCT Column1) WHERE Column2 = 'Migrate'
0
tim_csCommented:
An example to play with.

http://sqlfiddle.com/#!3/c9a8a/6/0
0
rayluvsAuthor Commented:
Thanx All !!!!
0
rayluvsAuthor Commented:
Thanx!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.