views:

209

answers:

1

I have a table with four columns:

PartNumber, ValvePartNumber, ActuatorPartNumber, Price

I want to find the number of distinct prices for each combination of ValvePartNumber and ActuatorPartNumber.

This is using SQL Server 2005

+5  A: 

You can combine COUNT(DISINTCT) and GROUP BY to accomplish this.

SELECT ValuePartNumber, ActuatorPartNumber, COUNT(DISTINCT Price) AS Prices
FROM [Table]
GROUP BY ValuePartNumber, ActuatorPartNumber
Jonathan Lonowski
I did not know that you could use COUNT and DISTINCT together like that. That makes it nice and simple. Thanks
Ross Goddard