日期:2014-05-18 浏览次数:20688 次
declare @t table (id int) insert into @t select 1 union all select 2 union all select 3 union all select 4 union all select 5 select id,ltrim(id*100/(select count(1) from @t))+'%' as 计算 from @t /* id 计算 ----------- ------------- 1 20% 2 40% 3 60% 4 80% 5 100% */
------解决方案--------------------
declare @t table (数量 int)
insert into @t
select 100 union all
select 200 union all
select 300 union all
select 400
select *,(select sum(数量) from @t where 数量<=t.数量) as 合计 from @t t
/*
数量 合计
----------- -----------
100 100
200 300
300 600
400 1000
*/