日期:2014-05-17  浏览次数:20786 次

请问一分类合并统计语句
A表  

ID     b     c     (3字段)
1       1     0
2       1     0  
2       0     1
3       0     1

用一语句合并结果为
ID     B       C

1       1       0
2       1       1
3       0       1  

所有写0的地方可以不写,要求就是sqlserver和oracle都可以用,简单明了,help~~~~



------解决方案--------------------
如果数据就是你给的例子的数据,可以这样写
select id, max(b),max(c) from a group by id
------解决方案--------------------
select a.id,sum(a.b),sum(a.c)
from A a
group by a.id;

这样可以吗?嘿嘿

------解决方案--------------------
用max可以

select tt.ID,max(tt.a),max(tt.b)
from (
select 1 as ID, 'Y ' as a, ' ' as b from dual union all
select 2 as ID, 'Y ' as a, ' ' as b from dual union all
select 2 as ID, ' ' as a, 'Y ' as b from dual union all
select 3 as ID, 'Y ' as a, ' ' as b from dual
)tt
group by tt.ID;