Count grouping by week

Asked

Viewed 2,000 times

1

I have a table in Mysql and am trying to group it by week(it may be week of 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, researched and did not find a function to return the week of the year, if anyone has any tips thank you.

  • 1

    have a look here http://www.w3resource.com/mysql/date-time-functions/mysql-week-function.php

  • I tried that, but it didn’t seem to work for me, anyway thank you

1 answer

1


There is a Mysql function that gives you a concaternation between the year and the 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;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.