日期:2014-05-16 浏览次数:20880 次
select PCode, PCount=sum(PCount) from tb group by PCount;
------解决方案--------------------
--> 测试数据:[test] if object_id('[test]') is not null drop table [test] create table [test]([PCode] int,[PCount] int) insert [test] select 5,1 union all select 6,0 union all select 7,0 union all select 5,1 union all select 6,2 union all select 7,0 union all select 5,0 union all select 6,2 union all select 7,0 union all select 6,2 union all select 8,1 select [PCode],SUM([PCount]) as [PCount] from test group by [PCode] /* PCode PCount 5 2 6 6 7 0 8 1 */