日期:2014-05-18 浏览次数:20935 次
--创建环境 drop table test create table test(strName varchar(10),score numeric(9,2),sumscore numeric(9,2)) insert into test select 'A',20,100 union select 'B',40,100 union select 'C',50,100 union select 'D',80,100 --执行语句 select strName,score,sumscore,convert(varchar,convert(numeric(9,2),score/sumscore)*100)+'%' as '比例' from test --执行结果 strName score sumscore 比例 ---------- ----------- ----------- ------------ A 20.00 100.00 20.00% B 40.00 100.00 40.00% C 50.00 100.00 50.00% D 80.00 100.00 80.00% --(所影响的行数为 4 行)