I have searched all the SQL questions and I have found every version of what I don’t want – so I need to ask. I am in a brain lock – knowing there is a count and sum and group and a join all thrown together.
2 Tables
- CustomerTable – CustID, CustQuality (values are good customer, bad customer, new customer etc)
- PurchaseTable (PurchID, PurchItem, PurchDate)
I am trying to count how many purchases by Good, Bad, New Customers in the last 30 days.
I have tried the join and group count etc and I keep getting:
- GoodCustomer – CustID2 – 1 purch
- GoodCustomer – CustID3 – 3 purch
- GoodCustomer – CustID4 – 2 purch
- BadCustomer – CustID7 – 2 purch
- BadCustomer – CustID1 – 4 purch
- NewCustomer – CustID9 – 1 purch
- NewCustomer – CustID4 – 4 purch etc etc.
I just want the overall results
- 3 Good Customers made 6 Purchases
- 2 Bad Customers made 6 Purchases
- 2 New Customers made 5 Purcahses
THEN FOR ADDITIONAL functioning… I have a 3rd table that I need to join as well. CustomerLocation (CLID, CLLocation (values of North, South, East, West))
So if I wanted to know the following break down of the groups
- 3 Good Customers made 6 Purchases – 1 Customer was from the North, 2 Customers From South
- 2 Bad Customers made 6 Purchases – 5 Customer from East, 1 West
- 2 New Customers made 5 Purcahses – 2 Customer from South
And the last new query would be…
WHERE CLLocation = South
Or if I wanted to look up by region…
- 1 Good Customers made 3 Purchases
- 2 Bad Customers made 2 Purchases
- 0 New Customers made 0 Purcahses
I KNOW I AM ASKING A LOT – BUT ANY AND ALL HELP WOULD BE GREATLY APPRECIATED!
1 Answer