Count grouping per week

1

I have a table in MySQL and am trying to group it by week (may be week of the year)

Select count(id),month(data_tarefa), year(data_tarefa) from tarefas group by mes, ano

So it works cool, but I would need to group by week, I researched and did not find a function to return the week of the year, if anyone has any tips thanks.

    
asked by anonymous 17.02.2014 / 16:49

1 answer

1

There is a MySQL function that gives you a concaternation between year and week of the year, called YEARWEEK() . Use it to get what you want.

SELECT count(id), YEARWEEK(data_tarefa) anosemana
FROM tarefas
GROUP BY anosemana;
    
17.02.2014 / 16:58