日期:2014-05-18 浏览次数:20453 次
create table tb(Debt varchar(10),Grp varchar(10),Name varchar(10),Score int) insert into tb values('部门1', '组1', '员工1', 1) insert into tb values('部门2', '组1', '员工2', 3) insert into tb values('部门1', '组2', '员工3', 2) insert into tb values('部门1', '组1', '员工4', 1) go select isnull(debt,'合计') debt,isnull(grp,'') grp,sum(score) score from tb group by debt,grp with rollup order by debt drop table tb /* debt grp score ---------- ---------- ----------- 部门1 组1 2 部门1 组2 2 部门1 4 部门2 组1 3 部门2 3 合计 7 */