我有这样的SQL语法:
select count(id) as total, date(created_at) as date from `posts` where `created_at` between '2018-08-01' and '2018-08-31' group by `date`
它返回(以JSON格式):
[
{
total: 3,
date: "2018-08-21"
},
{
total: 3,
date: "2018-08-30"
},
]
我不明白的是如何返回之间的所有日期,当没有值时,返回的总值为零。
预期如下:
[
{
total: 0,
date: "2018-08-01"
},
{
total: 0,
date: "2018-08-02"
},
...
...
{
total: 3,
date: "2018-08-21"
},
...
...
{
total: 3,
date: "2018-08-30"
},
...
...
{
total: 0,
date: "2018-08-31"
},
]
我希望你明白我的意思。感谢您的帮助。