MySQL查询最近几天的日期

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014248473/article/details/88227494

sql:

SELECT @s :=@s + 1 as 'index', DATE(DATE_SUB(CURRENT_DATE, INTERVAL @s DAY)) AS 'date' FROM mysql.help_topic,(SELECT @s := -1) temp WHERE @s < 7 ORDER BY 'date' ;

结果:

index

date

0

2019-03-06

1

2019-03-05

2

2019-03-04

3

2019-03-03

4

2019-03-02

5

2019-03-01

6

2019-02-28

7

2019-02-27

猜你喜欢

转载自blog.csdn.net/u014248473/article/details/88227494