日期:2014-05-17 浏览次数:20655 次
if object_id('[TB]') is not null drop table [TB]
go
create table [TB] (学生 nvarchar(2),得分 nvarchar(12),百分比 nvarchar(6))
insert into [TB]
select 'A','90-100','20%' union all
select 'B','80-89','40%' union all
select 'C','60-79','30%' union all
select 'D','60以下','10%'
select * from [TB]
SELECT tb.* ,
( SELECT CONVERT(VARCHAR, SUM(CONVERT(INT, SUBSTRING(百分比, 0, 3))))
+ '%'
FROM TB A
WHERE A.学生 <= TB.学生
) AS Nw
FROM dbo.TB
/*
学生 得分 百分比 Nw
A 90-100 20% 20%
B 80-89 40% 60%
C 60-79 30% 90%
D 60以下 10% 100%*/