1

我有这样的查询

SELECT DATE(date) AS DateOnly, COUNT(DISTINCT(device_id)) AS nrUnique 
FROM `mytable`
WHERE date>='2013-10-04 18:32:04' and date<now()
GROUP BY DateOnly 
order by DateOnly

结果

2013-10-05 | 10
2013-10-08 | 5

我想生成这样的结果

2013-10-04 | 0
2013-10-05 | 10
2013-10-06 | 0
2013-10-07 | 0
2013-10-08 | 5

我已经在 postgresql 中使用这样的联合执行此操作

....
UNION
(SELECT 0 as count, date(generate_series('2013-10-04 18:32:04'::date, now(),'1 day')) as timestamp))

我怎么能用 MYSQL 做到这一点?

4

0 回答 0