Hi,
I'm not much expert in writing sql statements and i have a requirement to calculate the number of customers subscribed for product.
My table has data like this.
Table name: Customer_Details
HTML Code:
Customer_Id Product
c1 M1
c2 M3
c3 M3
c1 M2
c1 M3
c2 M4
c3 M2
c4 M1
c4 M3
c4 M4
c4 M5
I have another table PRODUCT_FLAG
HTML Code:
PRODUCT FLAG
M1 Y
M2 Y
M3 N
M4 N
M5 Y
I need to get the customer counts for products in such a way that
if a customer has multiple Products with flag as Y, then he should be counted as 1 regardless of how many products he had.
eg: if c1 has M1,M2,M3--> counted as 1
if c2 had M3,M4--> counted as 0 etc;
Finally I need to get the output as follows:
HTML Code:
Product distinct customer count
M1 2
M2 3
M3 1
Note:
If the customer has multiple products , that customer can be counted in any of the products.
Gurus, pls. help me write a query.