我有下面的查询,以获得特定日期的用户注册,它的作品发现除了当用户注册计数为零的那一天,我希望它显示为零计数。但是它似乎跳过了这个条目,
SELECT count( * ) AS total, a.Date AS created_dates
FROM (
SELECT (CURDATE() - INTERVAL c.number DAY) AS date
FROM (SELECT singles + tens + hundreds number FROM
( SELECT 0 singles
UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3
UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6
UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9
) singles JOIN
(SELECT 0 tens
UNION ALL SELECT 10 UNION ALL SELECT 20 UNION ALL SELECT 30
UNION ALL SELECT 40 UNION ALL SELECT 50 UNION ALL SELECT 60
UNION ALL SELECT 70 UNION ALL SELECT 80 UNION ALL SELECT 90
) tens JOIN
(SELECT 0 hundreds
UNION ALL SELECT 100 UNION ALL SELECT 200 UNION ALL SELECT 300
UNION ALL SELECT 400 UNION ALL SELECT 500 UNION ALL SELECT 600
UNION ALL SELECT 700 UNION ALL SELECT 800 UNION ALL SELECT 900
) hundreds
ORDER BY number DESC) c
WHERE c.number BETWEEN 0 and 364
) a
LEFT OUTER JOIN `users_tp` u
ON DATE(u.register) = a.Date
WHERE
( a.Date BETWEEN CURDATE() - INTERVAL 30 DAY AND CURDATE() )
AND u.origin_reg = 'mobile'
AND u.step!=5
GROUP BY a.Date
ORDER BY a.Date ASC;
2条答案
按热度按时间r6l8ljro1#
问题来自
JOIN
:这是一个LEFT JOIN
,这就是你想要的,但是WHERE
子句引用被联接的表:因此,它的行为类似于INNER JOIN
.要解决这个问题,需要将联接表中的条件从
WHERE
条款ON
合同条款JOIN
.更改此项:
收件人:
3pmvbmvn2#
另一种解决方案: