declare @t table(a varchar(10),b varchar(10),c int)
insert @t
select '001', '张三', 20 union all
select '002', '张三', 37 union all
select '003', '李四', 34 union all
select '005', '李四', 78 union all
select '006', '赵六', 68 union all
select '007', '赵六', 10
select a=min(b.a),b=a.b,c=a.c from
(select b,c=sum(c) from @t group by b) a inner join @t b
on b.b=a.b group by a.b,a.c order by a
declare @t table(a varchar(10),b varchar(10),c int)
insert @t
select '001', '张三', 20 union all
select '002', '张三', 37 union all
select '003', '李四', 34 union all
select '005', '李四', 78 union all
select '006', '赵六', 68 union all
select '007', '赵六', 10
select
a = right('00'+ rtrim((select count(*) from
(select top 100 percent cast(max(a) as int) as a,b,sum(c) as c from @t group by b order by 1) x where a <= t.a)),3),
b,c from
(select top 100 percent cast(max(a) as int) as a,b,sum(c) as c from @t group by b order by 1) t
/*结果
a b c
----------------------------------
001 张三 57
002 李四 112
003 赵六 78
*/