MySQL查询选择超过一周的行?
为此,您可以使用DATEDIFF()函数。当前日期时间如下-
select now(); +---------------------+ | now() | +---------------------+ | 2019-06-09 19:15:56 | +---------------------+ 1 row in set (0.00 sec)
让我们首先创建一个表-
create table DemoTable -> ( -> ShippingDate datetime -> );
使用插入命令在表中插入一些记录-
insert into DemoTable values('2019-06-01');
insert into DemoTable values('2019-06-02');
insert into DemoTable values('2019-06-14');
insert into DemoTable values('2019-05-21');使用select语句显示表中的所有记录-
select *from DemoTable;
输出结果
+---------------------+ | ShippingDate | +---------------------+ | 2019-06-01 00:00:00 | | 2019-06-02 00:00:00 | | 2019-06-14 00:00:00 | | 2019-05-21 00:00:00 | +---------------------+ 4 rows in set (0.00 sec)
以下是选择超过一周的行的查询。假设当前日期为“2019-06-09”。因此,将选择超过一周的行,即“2019-06-02”之前-
select *from DemoTable where DATEDIFF(now(),ShippingDate) > 7;
输出结果
+---------------------+ | ShippingDate | +---------------------+ | 2019-06-01 00:00:00 | | 2019-05-21 00:00:00 | +---------------------+ 2 rows in set (0.00 sec)
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短