0

How to Count(Distinct ID) where the Value is equal 1; possibly using ROW_NUMBER() OVER(PARTITION BY ... ) ?

enter image description here

1

1 Answer 1

1

From the data you have supplied, we are able to deduce that you need to determine the count of distinct ID for each GROUP and YRMO where VALUE = 1 and designate it as a distinct count.

The COUNT(CASE WHEN condition THEN column END) syntax allows us to calculate the number of rows that match a condition :

SELECT GRP, YRMO, COUNT(DISTINCT CASE WHEN val = 1 THEN id END) AS distinct_counts, 
                  COUNT(DISTINCT id) AS total_counts
FROM mytable
GROUP BY GRP, YRMO
Sign up to request clarification or add additional context in comments.

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.