I need to do a graphic of the arithmetic mean (I don’t know if this is the correct word, sorry) between to dates and get the mean of hours for monday, tuesday… sunday. The hours per day of the week.
The table has the column log_date and I have an start day and end day and actually I do:
SELECT id, log_hours FROM log WHERE log_date >= DATE('2011-01-01') AND log_date <= DATE('2011-10-31')
This will give me the id’s between this two dates. But I don’t need this. What I need is a medium for monday, tuesday, etc. each day of the week to know what’s the normal hours done everyday of it.
How I can do it? I’m also coding in PHP
UPDATE:
What I finally need:
MONDAY: 3, 4, 10, 12, 5, final result => 6,8
TUESDAY: 2, 8, 8, 2, 1, final result => 4,2
WENDSDAY: 1, 1, 10, 5, 2, final result => 3,8
THURDAY 8, 10, 12, 5, 6, final result => 6,2
FRIDAY: 1, 1, 1, 1, 1, final result => 1
SATURDAY: 0, 8, 2, 0, 1, final result => 2,2
SUNDAY: 0, 0, 0, 0, 0, final result => 0
Thanks in advance!
You can use the DAYOFWEEK function to select values from a certain day. This query will give you the average of log_hours from each day in a single query: