MySQL BIGINT UNSIGNED值超出范围,乘以(-1)

时间:2011-11-12 13:50:50

标签: mysql

  

可能重复:
  BIGINT Out-of-range Error since MySQL 5.5

任何人都有任何想法为什么以下产生1690错误:BIGINT UNSIGNED值超出或范围?

SELECT CAST(IF(trades.`buyer` = 63, -1, 1)  * trades.`price` * trades.`amount` AS SIGNED) AS priceTotal 
FROM trades
WHERE (trades.`buyer` = 63 OR trades.`seller`= 63);

我想做的是当用户是买家时使priceTotal为负。

1 个答案:

答案 0 :(得分:6)

无符号值必须为零或更多 - 因此-1超出范围。不要使用unsigned may?

来自data type文档:

  

BIGINT[(M)] [UNSIGNED] [ZEROFILL]

     

一个大整数。签名范围是-9223372036854775808到   9223372036854775807。无符号范围为018446744073709551615

或者在混合符号上下文中使用它时将每个值转换为signed,这样的事情可能是:

IF(trades.`buyer` = 63, -1, 1) * CAST(trades.`price` AS SIGNED) * CAST(trades.`amount` AS SIGNED)