Reputation: 172
I have a table having three columns:
A B C 1 2 2 2 2 2 3 1 1 4 1 2
I want the count of those values which have C equal to 2 but with distinct values of B
So in this case for C = 2, count = 2 (B=2 and B=1)
I used the following command:
Select count(*) from mytable where C=2 group by (B)
but it yields:
count(*) 3
I have tried using "distinct" but it can't be use to select from one column
Upvotes: 0
Views: 1491
Reputation: 4652
Have you tried
SELECT COUNT(DISTINCT B) FROM mytable WHERE C = 2;
Upvotes: 2
Reputation: 1849
Use sub query like this:
Select count(*) from (
select distinct B where c=2
)
Upvotes: 1