Kyrylo Kravets
Kyrylo Kravets

Reputation: 543

How to implement conditional COUNTIF in SQL?

I am new to SQL and facing the problem for the while. The question is how to create such Label column in SQL?

Goal: When group count is more than 1 it should be 'Y' otherwise 'N'

Here is what I do in Excel (please see screenshot).

Screenshot

Upvotes: 1

Views: 138

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269873

I think you want case with a window function:

select (case when count(*) over (partition by item) > 1 then 'Y' else 'N' end) as label

Upvotes: 1

Related Questions