Domanda

To simplify our lives at work, I wrote modules for our billing system allowing us to easily create "products" when we setup free Databases/DNS records and keep track of them in our billing software. Unfortunately, these are standalone entries rather than sub-entries of the paid products we include these services with.

I have realized now that we have thousands of Databases/DNS Records still setup where the customer's have since cancelled their other paid services.

I need to query each client's completely list of billing items and if they have either A) Database B) DNS Record C) Both and no other active services, terminate them.

My question is just logistically speaking, how can I do this? Each Product has a unique ID but I am just drawing a blank on how to check with these conditions.

È stato utile?

Soluzione

Do you want something like this?

select customerId
from customerproducts cp
group by customerId
having sum(case when product not in ('Database', 'DNS Record') then 1 else 0 end) = 0 and
       sum(case when product in ('Database', 'DNS Record' then 1 else 0 end) > 0

This returns all customers that have only 'Database' and 'DNS Record' products.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top