I have a not-very-normalized MySQL table with the following values:
customer_ID | date | score | sale
As I am scoring the "purchase experience", I would like to check the total sale value for each customer based on his last score. I do not mind about previous scores, just about last one.
Let's say I have:
customer_ID | date | score | sale
a | yesterday | 3 | 10
a | today | 6 | 35
b | today | 10 | 20
c | yesterday | 4 | 5
The result for customers purchases with score > 5 should be:
num of customers | total sale values
2 | 65
Any idea of how to create such query?
Edit:
What I want to know is how much has a customer spent in purchases in total, but just on customers whose last score was bigger than 5.
yesterday
is it really a literal string valueyesterday
?customer a
has a record dated 2 days before with a score of 6 and sale of 15, what will be the result? and how was total sale values calculated?