--1、查询连续的天
SELECTdate_format(date_sub('2022-08-10',INTERVAL( @i := @i -1)DAY),'%Y-%m-%d')AS times
FROM
mysql.help_topic
JOIN(SELECT @i :=1) c
WHERE
help_topic_id <=(TIMESTAMPDIFF(DAY,'2022-08-10','2022-08-20'));--2、查询连续的月
SELECTdate_format(date_sub('2022-08-10',INTERVAL( @i := @i -1)MONTH),'%Y-%m')AS times
FROM
mysql.help_topic
JOIN(SELECT @i :=1) c
WHERE
help_topic_id <=(TIMESTAMPDIFF(MONTH,'2022-08-10','2022-12-20'));--3、查询连续的季度
SELECTCONCAT_WS("-",if(QUARTER(date_sub('2022-08-10',INTERVAL(@i)QUARTER))=4&& @i !=1,@j := @j +1,@j),QUARTER(date_sub('2022-08-10',INTERVAL( @i := @i -1)QUARTER))) times
FROM
mysql.help_topic
JOIN(SELECT @i :=1,@j :=YEAR('2022-08-10')) c
WHERE
help_topic_id <=(TIMESTAMPDIFF(QUARTER,'2022-08-10','2023-12-20'));--4、查询连续的年
SELECTdate_format(date_sub('2022-08-10',INTERVAL( @i := @i -1)YEAR),'%Y')AS times
FROM
mysql.help_topic
JOIN(SELECT @i :=1) c
WHERE
help_topic_id <=(TIMESTAMPDIFF(YEAR,'2022-08-10','2023-12-20'));--5、业务数据
SELECTCONCAT(YEAR(s.created_time),"-",QUARTER(s.created_time))AS quarter
FROM order_sell s
GROUPBYCONCAT(YEAR(s.created_time),"-",QUARTER(s.created_time))