用户数一周

时间:2015-06-12 05:56:30

标签: mysql sql

我必须得到一周的计数。

例如,如果我输入日期为'2014-04-06'

我的输出应该是

weekstart   weekend     weekcount                  
2014-04-06  2014-04-13   7                                                 

我正在使用id来计算。并创建了时间戳。 我已经得到了几周到sysdate的答案。

请查看Mysql查询。

1 个答案:

答案 0 :(得分:0)

您可以使用MYSQL的week()功能:

mysql> SELECT WEEK('2015-02-20',1);
    -> 8

<强> SQLFIDDLE DEMO

请注意:

M   F.day   Range   Week 1 is the first week …
0   Sunday  0-53    with a Sunday in this year
1   Monday  0-53    with more than 3 days this year
2   Sunday  1-53    with a Sunday in this year
3   Monday  1-53    with more than 3 days this year
4   Sunday  0-53    with more than 3 days this year
5   Monday  0-53    with a Monday in this year
6   Sunday  1-53    with more than 3 days this year
7   Monday  1-53    with a Monday in this year

M = Mode
F.day = First day of week