Mysql 如何通过unixstamp获得在过去24小时内不超过900秒的线路
如何通过unixstamp获得在过去24小时内不超过900秒的线路?谢谢Mysql 如何通过unixstamp获得在过去24小时内不超过900秒的线路,mysql,datetime,timestamp,Mysql,Datetime,Timestamp,如何通过unixstamp获得在过去24小时内不超过900秒的线路?谢谢 CREATE TABLE `users` ( `id` int(10) UNSIGNED NOT NULL, // User ID `regdate` int(10) UNSIGNED NOT NULL DEFAULT '0', // Registration date in UNIX timestamp `lastactive` int(10) UNSIGNED
CREATE TABLE `users` (
`id` int(10) UNSIGNED NOT NULL, // User ID
`regdate` int(10) UNSIGNED NOT NULL DEFAULT '0', // Registration date in UNIX timestamp
`lastactive` int(10) UNSIGNED NOT NULL DEFAULT '0', // Last active date in UNIX timestamp
`lastvisit` int(10) UNSIGNED NOT NULL DEFAULT '0', // Last visit date in UNIX timestamp
`lastpost` int(10) UNSIGNED NOT NULL DEFAULT '0' // Last post date in UNIX timestamp
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `users` (`id`, `regdate`, `lastactive`, `lastvisit`, `lastpost`) VALUES (13, 1569915390, 1583430726, 1583425902, 1583378778);
/*
* regdate = 1569915390 = Tuesday, October 1, 2019 7:36:30 AM
* lastactive= 1583430726 = Thursday, March 5, 2020 5:52:06 PM
* lastvisit = 1583425902 = Thursday, March 5, 2020 4:31:42 PM
* lastpost = 1583378778 = Thursday, March 5, 2020 3:26:18 AM
*
* 1. On connection and other activity, the lastactive is updated with time ()
*
* 2. If the session cookie is older than 900 seconds then lastvisit is updated from lastactive
*
* 3. When disconnected, lastvisit is updated from lastactive
*/
现在我的问题是:
SELECT id
FROM users
WHERE lastvisit > (NOW() - INTERVAL 24 HOUR) AND (NOW() - lastactive < 900)
选择id
来自用户
其中lastVisite>(现在()-间隔24小时)和(现在()-lastactive<900)
编辑:
我想我是在@tadman的帮助下找到的
SELECT *
FROM users
WHERE lastvisit < (NOW() - INTERVAL 24 HOUR) AND lastactive < (NOW() - INTERVAL 900 SECOND)
选择*
来自用户
其中LastVisite<(现在()-间隔24小时)和lastactive<(现在()-间隔900秒)
以下是解决方案:
SELECT *
FROM users
WHERE lastvisit < (NOW() - INTERVAL 24 HOUR) AND lastactive < (NOW() - INTERVAL 900 SECOND)
选择*
来自用户
其中LastVisite<(现在()-间隔24小时)和lastactive<(现在()-间隔900秒)
MySQL真正倾向于使用DATETIME
记录,而不是UNIX时间戳类型的值。使用InnoDB代替破旧的MyISAM遗留引擎也是一个好主意。您还需要使用默认的INT
(INT(11)
)值,而不是一些古怪和任意的INT(10)
值。对于示例行,您将如何计算900秒的值?不清楚要比较的时间值是哪一个。@tadman 900秒是一个固定的限制值,比较字段是lastvisit。仍然不清楚它应该代表什么。你是说在WHERE lastvisit>(现在()-间隔900秒)
?@tadman它完成了