-- 在PG里如果想做除法并想保留小数,用上面的方法却行不通,因为"/" 运算结果为取整,并且会截掉小数部分。
select 1/4; -- 0
select round(1/4,2); -- 0.00
select round(1::numeric/4::numeric,2); -- 0.25
select round(cast(1 as numeric)/cast(4 as numeric),2); -- 0.25
-- cast函数用法
select substr(cast(1234 as text),3,1); -- 3
PostgreSQL除法注意事项
最新推荐文章于 2024-03-12 10:52:57 发布