I want to compute scores for some data I have in a MySQL database. The score will be computed as follows:
score = COUNT(purchases MADE BETWEEN NOW() AND (NOW() - 1 WEEK))
+ 0.7 * COUNT(purchases MADE BETWEEN (NOW() - 1 WEEK) AND (NOW() - 2 WEEKS))
+ 0.4 * COUNT(purchases OLDER THAN (NOW() - 2 WEEKS))
I have purchses in a table with a purchase_time column.
Is it possible to do this in MySQL and get output similar to the following?
ORDER_ID SCORE
3 8
4 3
5 15
Thanks
— EDIT —
The table structure is:
tblOrder - table
id - primary key
created - time stamp
Your between and older need to be converted into CASE.
At the same time you can rewrite the expression so that specific cases are the factors such as