计算当前周的记录

时间:2016-05-23 08:03:10

标签: php mysql

我目前的数据库表有一个名为date的unix时间戳列。我试图获取本周每天计算的信息,例如

星期一:21 星期二:0 周三:3 瑟尔:8 周五:0 周六:0 太阳:0

我知道如何获取过去7天的信息,但是我需要这个只显示本周,所以如果今天是星期一,那么星期二将没有显示数据,因为星期二尚未到来。

任何指针都会受到赞赏。

2 个答案:

答案 0 :(得分:0)

这应该有效:

<强> SQL

var config = {};
config.selectMultiple = true;
CKFinder.define( config );

答案 1 :(得分:0)

试试这个;)

SELECT dayInWeek, SUM(cnt) AS cnt
FROM (
    SELECT
        DATE_FORMAT(dateline, '%a') AS dayInWeek,
        COUNT(1) AS cnt,
        WEEKDAY(dateline) AS idx
    FROM registrations
    WHERE WEEK(dateline, 1) = WEEK(NOW(), 1) GROUP BY WEEKDAY(dateline)
    UNION SELECT 'Mon' AS dayInWeek, 0 AS cnt, 0 AS idx
    UNION SELECT 'Tue' AS dayInWeek, 0 AS cnt, 1 AS idx
    UNION SELECT 'Wed' AS dayInWeek, 0 AS cnt, 2 AS idx
    UNION SELECT 'Thu' AS dayInWeek, 0 AS cnt, 3 AS idx
    UNION SELECT 'Fri' AS dayInWeek, 0 AS cnt, 4 AS idx
    UNION SELECT 'Sat' AS dayInWeek, 0 AS cnt, 5 AS idx
    UNION SELECT 'Sun' AS dayInWeek, 0 AS cnt, 6 AS idx) TMP
GROUP BY dayInWeek
ORDER BY idx