从带有时间戳值的MySQL表中获取两天的数据(今天和昨天)
让我们首先创建一个表-
mysql> create table DemoTable1495 -> ( -> ShippingDate bigint -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1495 values(1570127400); mysql> insert into DemoTable1495 values(1570213800); mysql> insert into DemoTable1495 values(1570645800); mysql> insert into DemoTable1495 values(1570300200);
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1495;
这将产生以下输出-
+--------------+ | ShippingDate | +--------------+ | 1570127400 | | 1570213800 | | 1570645800 | | 1570300200 | +--------------+ 4 rows in set (0.00 sec)
当前日期如下-
mysql> select curdate(); +------------+ | curdate() | +------------+ | 2019-10-06 | +------------+ 1 row in set (0.00 sec)
这是从MySQL获取两天数据的查询-
mysql> select * from DemoTable1495 -> where ShippingDate >=unix_timestamp(curdate() - interval 1 day) -> and -> ShippingDate < unix_timestamp(curdate() + interval 1 day);
这将产生以下输出-
+--------------+ | ShippingDate | +--------------+ | 1570213800 | | 1570300200 | +--------------+ 2 rows in set (0.00 sec)
热门推荐
10 读书祝福语女生短句简短
11 感谢同事新婚祝福语简短
12 感谢教官文案祝福语简短
13 员工聚会蛋糕祝福语简短
14 元宵发客户祝福语简短
15 给团队信心祝福语简短
16 医美的祝福语大全简短
17 异国姻缘的祝福语简短
18 兄妹拍照祝福语简短的话