要求在里面看 tb_user.create_time 里面看后30天,后60天的数据 怎么查找 谢谢啦!
用DATE_ADD()函数,可以得到后面30天,60天等时间。
select * from 表名 where time>= tb_user.create_time and time<=date_add(tb_user.create_time,INTERVAL 1 MONTH)
嗯,可以参考:
mysql> SELECT now() as 当前时间, ADDDATE(NOW(), INTERVAL 30 DAY) as 三十天后的时间;
+---------------------+---------------------+
| 当前时间 | 三十天后的时间 |
+---------------------+---------------------+
| 2021-08-20 14:52:06 | 2021-09-19 14:52:06 |
+---------------------+---------------------+
1 row in set (0.00 sec)
mysql> SELECT now() as 当前时间, ADDDATE(NOW(), INTERVAL 60 DAY) as 六十天后的时间;
+---------------------+---------------------+
| 当前时间 | 六十天后的时间 |
+---------------------+---------------------+
| 2021-08-20 14:52:27 | 2021-10-19 14:52:27 |
+---------------------+---------------------+
1 row in set (0.00 sec)
mysql> SELECT NOW() as 当前时间 ,SUBDATE(NOW(),INTERVAL 30 DAY) as 三十天前的时间;
+---------------------+---------------------+
| 当前时间 | 三十天前的时间 |
+---------------------+---------------------+
| 2021-08-20 14:53:24 | 2021-07-21 14:53:24 |
+---------------------+---------------------+
1 row in set (0.00 sec)
mysql>