如何显示MySQL中所有日期记录的下周日日期?
让我们首先创建一个表-
mysql> create table DemoTable(GetSundayDate date);
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('2019-08-07'); mysql> insert into DemoTable values('2018-09-05'); mysql> insert into DemoTable values('2019-09-12');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+---------------+ | GetSundayDate | +---------------+ | 2019-08-07 | | 2018-09-05 | | 2019-09-12 | +---------------+ 3 rows in set (0.00 sec)
以下是查询以获取列中所有日期的这个即将到来的星期日的日期-
mysql> SELECT date(GetSundayDate + INTERVAL 6 - weekday(GetSundayDate) DAY) AS ComingSundayDate from DemoTable;
这将产生以下输出-
+------------------+ | ComingSundayDate | +------------------+ | 2019-08-11 | | 2018-09-09 | | 2019-09-15 | +------------------+ 3 rows in set (0.00 sec)