SQL分类汇总,将汇总数据放在明细最后一条记录,但不另起一行
SQL分类汇总,将汇总数据放在明细最后一条记录,但不另起一行
如何用SQL查询语句实现这样的总计效果
姓名 数量 总计
A 1
A 1 2
B 1
B 2 3
分类汇总,将汇总数据放在明细最后一条记录,但不另起一行
请高手指点一下啊!首次提问,没有分数,还请谅解!
[解决办法]
declare @tb table (name varchar(10),num int)insert into @tb select 'A',1insert into @tb select 'A',1insert into @tb select 'B',1insert into @tb select 'B',2select *,id=identity(int,1,1) into # from @tbselect name,num,sumnum=case when id=(select max(id) from # where name=tp.name) then (select sum(num) from # where name=tp.name and id<=tp.id) end from # tp