#查詢近半年的資料 select * from youTable where time_colume>=curdate()- interval 6 month #查詢近3年的資料 select * from youTable where time_colume>=curdate()- interval 3 year
2.按月份彙總資料
#查詢近半年的資料,並且按照月份彙總
select concat(year(time_colume),month(time_colume)) as data, sum(amount) as total_amount
from youTable where time_colume>=curdate()- interval 6 month
group by month(time_column)
#查詢近3年的資料,並且按照月份彙總
select concat(year(time_colume),month(time_colume)) as data, sum(amount) as total_amount
from youTable
where time_colume>=curdate()- interval 3 year
group by month(time_column)