주간

SELECT DATE_FORMAT(date,'%Y-%c %u') Month 

, AVG(battery) AVG 

FROM car_date_history 

WHERE DATE BETWEEN DATE_SUB(CURDATE(),INTERVAL 21 DAY) AND CURDATE() AND car_id = 54

GROUP 

BY WEEK(date) 

ORDER 

BY date DESC;



월간

SELECT DATE_FORMAT(date,'%Y-%c') Month 

, AVG(battery) AVG 

FROM car_date_history 

WHERE DATE BETWEEN DATE_SUB(CURDATE(),INTERVAL 90 DAY) AND CURDATE() AND car_id = 54

GROUP 

BY MONTH(date) 

ORDER 

BY date DESC;




년간

SELECT DATE_FORMAT(date,'%Y') year 

, AVG(battery) AVG 

FROM car_date_history 

WHERE DATE BETWEEN DATE_SUB(CURDATE(),INTERVAL 3 YEAR) AND CURDATE() AND car_id = 54

GROUP 

BY YEAR(date) 

ORDER 

BY date DESC;

'DataBase' 카테고리의 다른 글

JOIN 의 종류  (0) 2018.08.27
MySQL TRUNCATE Table data 지우기  (0) 2018.08.27
MySQL foreign key drop 오류  (0) 2018.08.27
putty 환경 mysql 명령어  (0) 2018.08.10
[DB] web에서 erd 그려주는 사이트  (0) 2018.08.09

+ Recent posts