2014-06-17 5 views
0

지난 3 개월간의 데이터를 얻거나 'x'월부터 'y'개월까지 데이터를 얻는 일반적인 질문이 있습니까?지난 3 개월간의 데이터를 얻으려고 시도

저는 mysql을 처음 사용합니다. 도움이 필요해. 달의 첫 시작

select * from table where 
timestamp >= now()-interval 3 month; 

지난 3 개월 : 현재 날짜에서

답변

3

최근 3 개월

select * from table where 
timestamp >= last_day(now()) + interval 1 day - interval 3 month; 

이전 3개월

select * from table where 
month(timestamp) < month(now()) and 
timestamp >= last_day(now()) + interval 1 day - interval 4 month; 
받기
관련 문제