我需要修整尾随的0和小数点,我尝试了以下代码,但它不起作用。我使用的是PostgreSQL,最终结果看起来像(从显示1234.00到“ 1234 ft”)
SELECT TRIM(TRAILING "0" FROM ROUND("Length"::numeric * 3.28084, 2)) || ''ft'' AS "Length"
我得到的错误代码:
ERROR: column "Length" does not exist
LINE 1: SELECT TRIM(TRAILING '0' FROM ROUND("Length"::numeric * 3.28...
^ ^
答案 0 :(得分:0)
尝试一下:
select concat(substring(cast(cast(1234.00 as decimal(10,2)) as varchar(50)),1,
position('.' in cast(cast(1234.00 as decimal(10,2)) as varchar(50)))-1),' ft')
as Length
测试结果:
更新:
我刚刚找到了一个简单的
select concat(cast(1234.00 as decimal(10,0)),' ft') as Length
from ...
用您的列名替换1234.00并添加'from'子句。
答案 1 :(得分:0)
我会做:
SELECT ("Length"::numeric * 3.28084)::int || 'ft' as Length
您也可以round()
。关键是要转换为整数,这样就没有小数位。