mysql - mysql 出现超出范围错误

标签 mysql

我试图使用mysql实现黑客新闻算法并得到以下错误

    Double value is out of range in 
    pow(((unix_timestamp() - unix_timestamp(postDateTime))/3600 + 1),1.5)

Where the value of postDateTime is 2012-12-15 10:41:31

如果我将上述实现为

pow(((unix_timestamp() - unix_timestamp(cast(postDateTime as signed)))/3600 + 1),1.5)

它工作完美,但我不明白其背后的原因

最佳答案

您运行的 mysql 版本是什么?检查this link出来。

并检查the documentation了解为什么您会得到负值:

If called with no argument, returns a Unix timestamp (seconds since '1970-01-01 00:00:00' UTC) as an unsigned integer. If UNIX_TIMESTAMP() is called with a date argument, it returns the value of the argument as seconds since '1970-01-01 00:00:00' UTC. date may be a DATE string, a DATETIME string, a TIMESTAMP, or a number in the format YYMMDD or YYYYMMDD. The server interprets date as a value in the current time zone and converts it to an internal value in UTC.

...

If you want to subtract UNIX_TIMESTAMP() columns, you might want to cast the result to signed integers. See Section 12.10, “Cast Functions and Operators”.

关于mysql - mysql 出现超出范围错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13891809/

相关文章:

MySQL从空格分隔的字符串中选择比较数字

python - 如何使用 Python 将列表的列表插入数据库

php - php 中的 echo 没有显示回 HTML 页面

php - 将一个单元格的值超链接到另一个单元格

php - 将数字添加到自身并仅打印最后一个值的更好方法

php - 根据mysql中的不同条件选择两列

mysql - INSERT...ON DUPLICATE KEY UPDATE..... 有两个关键字段

mysql - 具有约束 "UNIQUE"的列如何在 mysql -server 5.7 中接受重复值

mysql - SQL ALTER TABLE 添加主键错误 1064

mysql - 如何使用 MySQL 计算每个组的用户数?