一、mysql获取近10年的年份:
select year(now()) as c_year union all
select year(now())-1 as c_year union all
select year(now())-2 as c_year union all
select year(now())-3 as c_year union all
select year(now())-4 as c_year union all
select year(now())-5 as c_year union all
select year(now())-6 as c_year union all
select year(now())-7 as c_year union all
select year(now())-8 as c_year union all
select year(now())-9 as c_year
二、mysql获取近10年的数据:
按年份获取:select * from tablename where c_year>year(now())-9
按日期获取:select * from tablename where c_date>date(date_add(now(),interval-9 year))
按时间获取:select * from tablename where c_time>date_add(now(),interval-9 year)
三、年份数据转为字符型
select "全部" as c_year union all
select cast(year(now()) as char) as c_year union all
select cast(year(now())-1 as char) as c_year union all
select cast(year(now())-2 as char) as c_year union all
select cast(year(now())-3 as char) as c_year union all
select cast(year(now())-4 as char) as c_year union all
select cast(year(now())-5 as char) as c_year union all
select cast(year(now())-6 as char) as c_year union all
select cast(year(now())-7 as char) as c_year union all
select cast(year(now())-8 as char) as c_year union all
select cast(year(now())-9 as char) as c_year