如何通过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 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)
编辑: 我想我是在@tadman
的帮助下找到的SELECT *
FROM users
WHERE lastvisit < (NOW() - INTERVAL 24 HOUR) AND lastactive < (NOW() - INTERVAL 900 SECOND)
答案 0 :(得分:1)
这是解决方案:
SELECT *
FROM users
WHERE lastvisit < (NOW() - INTERVAL 24 HOUR) AND lastactive < (NOW() - INTERVAL 900 SECOND)