20

3

Challenge Questions

So I created one query trying to answer challenge question #1: best 10 customers in past three months. I'm thinking about answering in the sense of who ordered the most (number of times) in the past three months, as oppose to who spent the most money. Anyways, here is my query:

SELECT customer_name, datetime, COUNT(cd.customer_name) FROM customer_data AS cd, order_data AS od
WHERE cd.customer_id = od.customer_id
GROUP BY od.customer_id
HAVING datetime > '2012-09-30'
ORDER BY COUNT(cd.customer_name) DESC
Limit 0,10;

Here are the results: 

customer_name datetime COUNT(cd.customer_name)
Vanessa Martin 2012-10-10 13:03:00 68
Kevin Southern 2012-11-03 09:03:00 62
George Holm 2012-12-27 04:51:00 61
Natasha Atkinson 2012-12-16 17:20:00 60
Kevin Martin 2012-11-22 23:32:00 60
Kelli Walker 2012-11-09 17:23:00 59
Sarah Kozikowski 2012-12-14 22:32:00 57
Carol Holm 2012-12-29 16:01:00 56
Carol Haffner 2012-10-26 22:59:00 55
Julie Weller 2012-11-07 01:04:00 55

I have a feeling this might be incorrect - would love some feedback


Comments

Please sign in or sign up to comment.