I have a sales table that has the fields customer_nbr, product_family and Sale_Date. I need to know which customers have been sold atleast 3 different products atleast 3 different times. Then I use an alias Status to get a count of those customers. I may be all wrong because my result is incorrect but heres My sql:
Select Distinct Status, count(status) as ct from
(Select distinct customer_nbr,
CASE
WHEN
Count(distinct product_family) > 2 and Count(distinct sale_date) > 2 Then 'D'
END as Status
From TableName
Group By Customer_nbr
) as qt
group by status
my results should be like STATUS = "D" CT = 1115
my problem is the count on both fields > 2 with the 'and' aren't using the same records.
Thank you in advance for anybodys help!!
Select Distinct Status, count(status) as ct from
(Select distinct customer_nbr,
CASE
WHEN
Count(distinct product_family) > 2 and Count(distinct sale_date) > 2 Then 'D'
END as Status
From TableName
Group By Customer_nbr
) as qt
group by status
my results should be like STATUS = "D" CT = 1115
my problem is the count on both fields > 2 with the 'and' aren't using the same records.
Thank you in advance for anybodys help!!