0

我有类似的查询

SELECT uq.timespan, COALESCE(tsq.TotalClicks, 0) as Clicks FROM (
SELECT '22-28 days' as timespan
union SELECT '15-21 days'
union SELECT '8-14 days'
union SELECT 'up to 7 days'
)uq LEFT JOIN (
SELECT CASE 
    WHEN submitdate >= NOW() - INTERVAL 4 WEEK
                AND submitdate < NOW() - INTERVAL 3 WEEK THEN '22-28 days'
    WHEN submitdate >= NOW() - INTERVAL 3 WEEK
                AND submitdate < NOW() - INTERVAL 2 WEEK THEN '15-21 days'
    WHEN submitdate >= NOW() - INTERVAL 2 WEEK
        AND submitdate < NOW() - INTERVAL 1 WEEK THEN '8-14 days'
    WHEN submitdate >= NOW() - INTERVAL 1 WEEK THEN 'up to 7 days'
           END Weeksubmitdate, 
           count(id) TotalClicks
FROM $survey
WHERE submitdate >= NOW() - INTERVAL 4 WEEK
GROUP BY Weeksubmitdate
)tsq ON uq.timespan = tsq.Weeksubmitdate

它的输出就像

22-28 days  4
15-21 days  1
8-14 days   1
up to 7 days    11

现在我想用工作日改变输出

mon-sun     2
mon-sun     0
mon-sun     7
mon-sun     5

假设现在我在星期四,这应该算在这周的星期一。

4

0 回答 0