Kris Markevich
Kris Markevich

Reputation: 3

Select Person with only one value in the column

I can't correctly write a query. I need to select a person who has only one value in the column. For example,

select * (
select PersonID, sum(TotalAmount)
from  Table1
group by PersonID
HAVING sum(TotalAmount) = 0 )
where Group = A

It means that I would select all customers that belong to ONLY 'A' group...

Could someone help me?

Upvotes: 0

Views: 995

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269443

If you want the persons with only one value, then having count(*) = 1 comes to mind:

select personid
from table1
group by personid
having count(*) = 1;

Upvotes: 1

Related Questions