我有一个相当简单的表,其中字段 lastloginon 是时间戳,其中存储的日期如下所示:2013-03-17 17:12:58
如何选择过去 20 分钟内的所有记录?
我正在尝试使用以下代码:
SELECT * FROM who_is_online WHERE lastloginon > (now() - interval 20 minute)
这会产生错误的结果集,即 qyery 在 15:30 执行它会显示 4 条记录,这些记录插入到:
2013-03-18 13:13:36
2013-03-18 13:35:12
2013-03-18 14:43:42
2013-03-18 14:55:34
有人知道我在做什么错吗?
这是表导出,只是希望有人能发现我做错了什么:
CREATE TABLE IF NOT EXISTS `who_is_online` (
`recid` int(11) NOT NULL auto_increment,
`username` varchar(255) default NULL,
`lastloginon` timestamp NOT NULL default CURRENT_TIMESTAMP,
`memberip` varchar(255) default NULL,
`sessionid` varchar(255) NOT NULL,
`active` tinyint(4) default NULL,
PRIMARY KEY (`recid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=17 ;
--
-- Dumping data for table `who_is_online`
--
INSERT INTO `who_is_online` (`recid`, `username`, `lastloginon`, `memberip`, `sessionid`, `active`) VALUES
(7, ' admin', '2013-03-17 14:43:43', '87.202.163.222', '7kve2idmdbd47aksab4j9hqg74', 1),
(8, ' mmitechnic', '2013-03-17 15:16:39', '5.54.84.144', 'mofgpldp2lu30enhitvak9m4t3', 1),
(9, ' theodor71', '2013-03-17 17:12:58', '85.75.243.246', '4enpk49oi7cg0blumgsd0lu0m7', 1),
(10, ' xElfiex', '2013-03-18 12:38:05', '5.55.27.203', 'tr003d6qbd71v2i5grnuako362', 1),
(11, ' admin', '2013-03-18 12:56:06', '85.74.166.110', '7kve2idmdbd47aksab4j9hqg74', 1),
(12, ' xElfiex', '2013-03-18 13:13:36', '5.55.27.203', 'tr003d6qbd71v2i5grnuako362', 1),
(13, ' admin', '2013-03-18 13:35:12', '85.74.166.110', '7kve2idmdbd47aksab4j9hqg74', 1),
(14, ' admin', '2013-03-18 14:43:42', '85.74.166.110', '7kve2idmdbd47aksab4j9hqg74', 1),
(15, ' admin', '2013-03-18 14:55:34', '85.74.166.110', '7kve2idmdbd47aksab4j9hqg74', 1),
(16, ' admin', '2013-03-18 15:32:27', '85.74.166.110', '7kve2idmdbd47aksab4j9hqg74', 1);
问候,佐兰