此查询收到错误#1690 - BIGINT UNSIGNED value is out of range
:
SELECT * FROM `user`
WHERE ROUND( ( UNIX_TIMESTAMP() - `expire` ) / 86400 ) = 7
我在Stackoverflow中阅读了有关此错误的信息,并查看了有关cast
的一些注意事项,但我无法将其应用于此查询。
答案 0 :(得分:1)
CREATE TABLE IF NOT EXISTS `user` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`expire` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ;
--
-- Dumping data for table `test`
--
truncate table user;
INSERT INTO `user` (`id`, `expire`) VALUES
(1, 1234567890),
(2, 1923456780),
(3, 1449397282),
(4,1449397282+3600); -- note this is based on this moment I am writing this about a day ahead
select id,expire,seconds from
( select id,expire,TIME_TO_SEC(TIMEDIFF(from_unixtime(expire), now())) as seconds
from user
) xDerived
where seconds>0 and seconds<604800; -- # of seconds in a week
+----+------------+---------+
| id | expire | seconds |
+----+------------+---------+
| 4 | 1449400882 | 2870 |
+----+------------+---------+
所有尚未过期的事情,但会在一周之内
答案 1 :(得分:1)
表格中的第二个值会给出否定结果,因此您会收到错误。
要在您的案例中使用否定结果,请在查询前使用
SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';