mysql日期补全
前提:订单表,有的日期没有订单,但是也要查询出来,并分页
查询order表中2017-10-01 ----2017-10-31 已10 分页 查询出每天的订单数,没有的补0
SELECT od.date, od.orderCount FROM ( SELECT count(*) orderCount, DATE_FORMAT(order_time, '%Y-%m-%d') date FROM order_info WHERE order_time > '2017-10-1' AND order_time < '2017-10-31' GROUP BY DATE_FORMAT(order_time, '%Y-%m-%d') UNION (SELECT 0, '2017-10-01') UNION (SELECT 0, '2017-10-02') UNION (SELECT 0, '2017-10-03') UNION (SELECT 0, '2017-10-04') UNION (SELECT 0, '2017-10-05') UNION (SELECT 0, '2017-10-06') UNION (SELECT 0, '2017-10-07') UNION (SELECT 0, '2017-10-08') UNION (SELECT 0, '2017-10-09') UNION (SELECT 0, '2017-10-10') UNION (SELECT 0, '2017-10-11') UNION (SELECT 0, '2017-10-12') UNION (SELECT 0, '2017-10-13') UNION (SELECT 0, '2017-10-14') UNION (SELECT 0, '2017-10-15') UNION (SELECT 0, '2017-10-16') UNION (SELECT 0, '2017-10-17') UNION (SELECT 0, '2017-10-18') UNION (SELECT 0, '2017-10-19') UNION (SELECT 0, '2017-10-20') UNION (SELECT 0, '2017-10-21') UNION (SELECT 0, '2017-10-22') UNION (SELECT 0, '2017-10-23') UNION (SELECT 0, '2017-10-24') UNION (SELECT 0, '2017-10-25') UNION (SELECT 0, '2017-10-26') UNION (SELECT 0, '2017-10-27') UNION (SELECT 0, '2017-10-28') UNION (SELECT 0, '2017-10-29') UNION (SELECT 0, '2017-10-30') UNION (SELECT 0, '2017-10-31') ) AS od LIMIT 10,10