Reputation: 3534
I'm trying to avoid involving php after this query. I have a table that holds a list of employees and how much time they worked in seconds,date, etc... i want to:
select SUM(`seconds`) between date A and date B group by WEEK(`date`)
that will give me results for each week but now i want to get an average seconds worked per week by using AVG() on the whole result set. How could you accomplish this in one query?
Upvotes: 0
Views: 161
Reputation: 911
This will do the trick:
Select AVG(sum_seconds) from (select SUM('seconds') as sum_seconds between date A and date B group by WEEK('date')) as a
Upvotes: 1
Reputation: 146
You can use something like this
select sum(total) from (select SUM(`seconds`) as total between date A and date B group by WEEK(`date`)) as tbl1
Hope it help
Upvotes: 2