BEGINDECLARE num intDEFAULT-1;CREATETEMPORARYTABLE under_日历 (
yyyy int,
q int,
mm int,
dd VARCHAR(15),
w INT,
wd VARCHAR(15));
lp:LOOPset num = num+1;insertinto under_日历
selectyear(CURDATE())as y,
floor((date_format(DATE_ADD(DATE_SUB(CURDATE(),INTERVAL dayofyear(now())-1DAY),INTERVAL num DAY),'%m')+2)/3)as q,
date_format(DATE_ADD(DATE_SUB(CURDATE(),INTERVAL dayofyear(now())-1DAY),INTERVAL num DAY),'%m')as M,
date_format(DATE_ADD(DATE_SUB(CURDATE(),INTERVAL dayofyear(now())-1DAY),INTERVAL num DAY),'%Y-%m-%d')asdate,
date_format(DATE_ADD(DATE_SUB(CURDATE(),INTERVAL dayofyear(now())-1DAY),INTERVAL num DAY),'%u')as W,case DAYOFWEEK(date_format(DATE_ADD(DATE_SUB(CURDATE(),INTERVAL dayofyear(now())-1DAY),INTERVAL num DAY),'%Y-%m-%d'))-1when1then'星期一'when2then'星期二'when3then'星期三'when4then'星期四'when5then'星期五'when6then'星期六'when0then'星期日'endas DW;if num=dayofyear(concat(YEAR(now()),'-12-31'))-1THENLEAVE lp;ENDif;ENDLOOP;select*from under_日历;DROPTABLE under_日历;END