我想按周计算一系列计数。我知道使用week()函数返回一周的数字,但我喜欢这样的东西:
Week count(*)
Jan 1 - Jan 7 30
Jan 8 - 14 50
and so on...
有办法做到这一点吗?非常感谢你。
答案 0 :(得分:0)
select
concat(cast(DATE_ADD(yourdate, INTERVAL(1-DAYOFWEEK(yourdate)) DAY) as char), ' - ',
cast(DATE_ADD(yourdate, INTERVAL(7-DAYOFWEEK(yourdate)) DAY) as char))
as period, count(*)
from tablename
group by week(yourdate)