J-snow
J-snow

Reputation: 61

Using CASE to compare DISTINCT(COUNT()) and COUNT() columns

I want to run a query that will return 'Yes' when the distinct count and count return the same value. Below is the unsuccessful query.

SELECT
  DISTINCT(COUNT(colA)),
  COUNT(colA),
CASE
  WHEN DISTINCT(COUNT(colA)) = COUNT(colA) THEN 'Yes'
  ELSE 'Sad'
END
FROM tableA

Upvotes: 2

Views: 195

Answers (1)

eshirvana
eshirvana

Reputation: 24603

you need to count distinct like so :

SELECT
    COUNT(DISTINCT colA),
    COUNT(colA),
    CASE WHEN COUNT(DISTINCT colA) = COUNT(colA) THEN 'Yes' ELSE 'Sad' END
FROM tableA

Upvotes: 4

Related Questions