mysql 查询近30天的数据


近30天每一天的数据都显示
SELECT 
		  w.orderDate,ifnull(res.orderCount,0) as orderCount,ifnull(res.orderSum,0)
		FROM
		(
		SELECT DATE_SUB(CURDATE(), INTERVAL m.s-1 DAY) as orderDate from (
		SELECT 1 as s UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7
    UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12 UNION ALL SELECT 13 UNION ALL SELECT 14
    UNION ALL SELECT 15 UNION ALL SELECT 16 UNION ALL SELECT 17 UNION ALL SELECT 18 UNION ALL SELECT 19 UNION ALL SELECT 20 UNION ALL SELECT 21 UNION ALL SELECT 22
    UNION ALL SELECT 23 UNION ALL SELECT 24 UNION ALL SELECT 25 UNION ALL SELECT 26 UNION ALL SELECT 27 UNION ALL SELECT 28 UNION ALL SELECT 29 UNION ALL SELECT 30
    ) m
		) w
		LEFT JOIN 
		(
		SELECT COUNT(*) as orderCount,sum(f_downloads) as orderSum ,date(f_publish_date) as orderDate 
		from cms_info WHERE f_status = 'A' AND DATE_SUB(CURDATE(), INTERVAL 30 DAY)  <  date(f_publish_date) AND date(f_publish_date) <=   DATE(CURDATE()) 
		GROUP BY orderDate 
		)res ON w.orderDate = res.orderDate order by w.orderDate ASC


只显示有数据的日期

SELECT * FROM cms_info where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= f_publish_date;



你可能感兴趣的:(mysql)