user3200361 user3200361 - 9 months ago 51
SQL Question

Get rows which have a specific value occurring less than twice

I have an issue with a SQL query. I have a table as below

123 C
234 S
456 S
123 C
789 S

From the above table I need to get
which have occurrences with Status
appearing less than twice. Need help in figuring this out.

Answer Source

I'm not Oracle, but see if you can use this.

Select Employee_ID
From table
Where Status = 'C'
Group By Employee_ID
Having Count(Status) < 2