Link to home
Start Free TrialLog in
Avatar of Charles Baldo
Charles BaldoFlag for United States of America

asked on

Need count of values in table

Hello I have a table in MS SQL Server that looks like this

Instrument,  KitLot
1                 Z123
1                 Z123
1                 U101
1                 U101

I would want to know how many unique  kitLots there are  per instrument so the answer I am looking for here is   2

Thank You
ASKER CERTIFIED SOLUTION
Avatar of i2mental
i2mental
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Guy Hengel [angelIII / a3]
select count(*)
from ( select kitlot from yourtable group by kitlot where instrument = 1 ) as subquery


for all instruments:

select instrument, count(*)
from ( select instrument, kitlot from yourtable group by instrument, kitlot  ) subquery
group by instrument


Avatar of Charles Baldo

ASKER

Perfect Thanks a ton and just in time for my 9:30 meeting :)