I have both a MS SQL Database and a postgres database. A solution in either will work as I can translate it.
We have a customer_phone
table where the relevant columns are:
id, customer_id, phone, is_bad
What I need to do is select all the customer_id
's from this table that ONLY have is_bad = true
. So if you have 1 good phone number and 1 bad, you shouldn't appear.
For some reason I'm struggling to find an easy way to do this, I feel like it should be deceptively simple.
This was a start that gives me at least all the customers a count of their good and bad numbers, but I'm wondering if there is a way that doesn't involve having to use subqueries and in
's?
select customer_id, is_bad, count(customer_id)
from customer_phone cp
group by customer_id, is_bad
order by customer_id desc
1:N
or specific types!!