select case when length(mon)=1 then concat('2017-0',mon) else concat('2017-',mon) end months from (select @m:=@m+1 mon from tbl ,(select @m:=0) a ) aa limit 12;
…………………………………………………………………………
要取当年的:
select case when length(mon)=1 then concat(left(CURRENT_DATE,5),'0',mon) else concat(left(CURRENT_DATE,5),mon) end months from (select @m:=@m+1 mon from tbl ,(select @m:=0) a ) aa limit 12;
随便找一个大于12条记录的表执行下面的sql就得到你要的结果,不谢^_^
要取当年的: