Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当运行查询时:
select sum(items) from my_table where ...
我回来的结果(红宝石)是类型BigDecimal。有什么 SQL 魔法可以应用来找回int吗?
BigDecimal
int
NUMERIC在列上执行这样的操作时,您会得到 BigDecimal 结果。您可能想要的是在 Ruby 中使用collect操作将其转换,或者在 MySQL 级别通过在返回之前转换为整数:
NUMERIC
collect
SELECT FLOOR(SUM(items)) FROM my_table WHERE ...
select cast(sum(items) as binary) ...
对我来说效果很好