i have day, month, year, value columns in one table, here i need to get every week average value in one month.
how to get that. please help me regarding this.
select avg(value) from table group by month
gives month average.
select avg(value) from table group by day
gives day average.
but how to get week average from month field.
You can’t “get weeks from a month” as one is not a subset of the other.
The number of days (and hence weeks) in 1 month varies from month to month and only in non-leap years – and in February only – are there exactly 4 weeks in a month.
You should use the original date field and use a date function to limit/group the data by week.
get the week in mySQL with
WEEK(timestamp)or
YEARWEEK(timestamp)or
WEEKOFYEAR(NOW())or
DATE_FORMAT($yourDate, \'%X %V\') as week