0

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

1
  • it can't be use to select from one column - er... Commented Aug 22, 2017 at 11:28

2 Answers 2

2

Have you tried

SELECT COUNT(DISTINCT B) FROM mytable WHERE C = 2;
Sign up to request clarification or add additional context in comments.

Comments

1

Use sub query like this:

Select count(*) from (
    select distinct B where c=2
)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.