什么是包含从MySQL数据库生成的时间序列图的空日期的最佳方式。填写日期间隔mysql查询ajax调用
如果我运行一个查询来获取说所有的红色轿车在某一天卖的,我可以运行:
SELECT count(car_sale_order) as 'count', DATE(sale_date) as 'sale_date'
FROM car_sales
WHERE colour = "red";
但结果可能有日期孔在其中,即
------------------
count | sale_date
------------------
2 | 2017-09-03
10 | 2017-09-04
1 | 2017-09-07
23 | 2017-09-09
45 | 2017-09-10
2 | 2017-09-11
21 | 2017-09-12
当真正喜欢什么ID:
------------------
count | sale_date
------------------
2 | 2017-09-03
10 | 2017-09-04
0 | 2017-09-05
0 | 2017-09-06
1 | 2017-09-07
0 | 2017-09-08
23 | 2017-09-09
45 | 2017-09-10
2 | 2017-09-11
21 | 2017-09-12
我使用PHP所以知道,我可以生成这个东西在那边,但它将是非常方便的,只是有结果集包括这从一开始去....
这是不一样的What is the most straightforward way to pad empty dates in sql results (on either mysql or perl end)? 我正在寻找一个MySQL只导致
这可能有所帮助。 https://www.plumislandmedia.net/mysql/filling-missing-data-sequences-cardinal-integers/ –
这看起来真的很方便 - 生病看看谢谢 – aarcarr
结帐https://stackoverflow.com/questions/9295616/how mysql-select-query –