1、獲取最近7天的數據
1 SELECT * FROM "表名" 2 WHERE 3 DATE_SUB( CURDATE( ), INTERVAL 7 DAY ) <= date( "時間列名") )
2、獲取最近7天的數據並且按照天來分組
1 SELECT 2 DATE_FORMAT( "時間列名", '%Y-%m-%d' ) days, 3 count(*) count 4 FROM 5 6 ( SELECT * FROM "表名" 7 WHERE DATE_SUB( CURDATE( ), INTERVAL 7 DAY ) <= date( "時間列名") ) as "表別名" 8 9 GROUP BY 10 days;
