【发布时间】:2022-08-18 16:19:51
【问题描述】:
我有这个查询:
SELECT date AS datekey, count(*) AS total
FROM `tags` AS `t`
INNER JOIN `thing_tags` AS `tt` ON `tt`.`tag_id` = `t`.`tag_id`
INNER JOIN `things` AS `t` ON `tt`.`thing_id` = `t`.`thing_id`
WHERE `t`.`other_id` = 14
AND date(`date`) >= \'2019-12-20\'
GROUP BY datekey
ORDER BY datekey DESC
这给了我这些结果:
2022-07-15,8
2022-07-12,16
2022-07-06,10
2022-07-01,3
我需要的是每一天的记录,即使计数为零:
(record for every day since 2019-12-20)
2022-07-06,10
2022-07-05,0
2022-07-04,0
2022-07-03,0
2022-07-02,0
2022-07-01,3
我希望我可以使用某种日期函数来创建一个结构,然后我可以加入该结构,但我不知道该怎么做。