This is driving me crazy, I cant seam to manage this without massive amount of code, this is my sql table:
userid date orderValue
2 2012-01-01 2000
1 2012-01-01 3000
1 2012-01-01 5000
1 2012-01-02 5000
2 2012-01-02 8000
2 2012-01-02 8000
For each month I need to get the mean value per user from the first date ever intill the current month.
The output I’am looking for is something along the line of
$orderArray[$month][$userid][‘mean’]
I don’t relay need the code, jut need to get my mind out the current thoughts that man stuck on. How would you go about solving this?
Something along the lines of:
Note that I’m using
DATE_FORMATinstead ofMONTH. If you don’t do this, January 2012 and January 2013 would effectively be merged, which I guess is not what you want.You’ll have to create the desired result array yourself in PHP by iterating over the SQL result set and putting each mean value in the appropriate place.