Forum Moderators: open
I'm trying to create a targeted email marketing list from my customers in my database. I want to be able to create three different marketing lists and am a little stumped on how to get the query to do what I want. I confess to being a mysql query newbie... but with that said I'm made a valiant attempt to accomplish this query (2 hours of trying) and now need some help to wrap this up
So I have a query that I've written that is accomplishing about half of what I need it to do and now I'm stumped!
List 1: I want to market to people that have only purchased "#*$!xx" product from me since 01/01/2007. So the query that I have is the following:
SELECT o.customers_id, o.customers_name, o.customers_email_address, o.orders_id, op.products_model
FROM orders o, orders_products op
WHERE o.orders_id=op.orders_id
AND o.date_purchased >= "2007-01-01"
AND op.products_model=#*$!xx
GROUP BY o.orders_id
So this will return all orders that have been made with product #*$!xx. However, it doesn't tell me if these customers have ordered again or not. So my thought is if I can have the query only return the customers that have ordered #*$!xx product and have only placed one order. so something like count of o.customers_id = 1 .... I've tried a few times to get this to work but I don't understand the count function or something. Any thoughts?
List2: This is the same as list 1 except a different product, product "yyyyy". So the query will be the same just with a different op.products_model
List 3: I need to have a list of customers that placed an order between January 1, 2007 and July 1, 2007 that haven't placed an order since July 1,2007. I also need to weed out the customers that showed up on the first two lists so I don't re-email them a marketing message. So the below query will give me the customers that have ordered between the dates I mentioned but how the freak do I get it to only return the orders between those dates that haven't ordered again after July? And how do I get it to exclude people from above?
Here is my query:
SELECT o.customers_id, o.customers_name, op.products_model, o.customers_email_address, o.orders_id
FROM orders o, orders_products op
WHERE o.date_purchased >= "2007-01-01" AND o.date_purchased < "2007-07-01"
GROUP BY o.orders_id
My thought is that I could look for the customers_id after the date of 07/1/2007 and if it is found then don't include that customers_id in the results of the query. My problem is I have no idea how to translate that into the query. Any helped appreciated. Also how to get rid of customers that ordered the two products mentioned in list 1 and list 2? My thought is do something like:
NOT op.products_model=#*$!xx AND NOT op.products_model=yyyyy
Thanks for any help!