SQL保留一位小数

来源:百度知道 编辑:UC知道 时间:2024/05/18 02:53:51
想实现如下功能:
字段a/字段b,保留一位小数并用百分数显示

select (cast(round(a/b,1) as varchar(200))+'%') 新列名 from 表名
注意下你 a,b列的类型 int的话 点后全是0

declare @a float,@b float,@c float
set @a=1
set @b=3
set @c=@a/@b *100

select cast(CAST(@c as numeric(10,1)) as char)+'%'

select (cast(round(cast(a as money)/b,1) as varchar(200))+'%') NewColumnName from YourTable