select
count(stuno),
sum(是否通过),
ltrim(cast(sum(是否通过)*100.0/(case count(stuno) when 0 then 1 else count(stuno) end) as dec(18,2)))+'%' from dd
select*from dd
count(stuno),
sum(是否通过),
ltrim(cast(sum(是否通过)*100.0/(case count(stuno) when 0 then 1 else count(stuno) end) as dec(18,2)))+'%' from dd
select*from dd
或者给个更容易明白的 不超出我给的代码的范围
谢谢
原本的用途是用来去掉字符串左边的空格,在这里就是把数字转成字符
看看下面两个方式的比较declare @s int
set @s=100select convert(varchar,@s)+'abc'select ltrim(@s)+'abc'/**
---------------------------------
100abc(所影响的行数为 1 行)
---------------
100abc(所影响的行数为 1 行)
**/