如果数据就是你给的例子的数据,可以这样写 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;这样可以吗?嘿嘿
如果sum的话你可以使用decode select a.id,sum(decode(a.b,'是',1,0)),sum(decode(a.c,'是',1,0)) 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;
回 hongqi162(失踪的月亮) 那个decode在sqlserver 里应该是不能用
在sqlserver里用sum(case when '是' then 1 else 0 end)
恩我是不想再在sqlserver里换语句了,头痛,呵呵
在bobfang(匆匆过客)基础上加两个转换,哈哈,笨了点,但是能得到结果啊! ID b c (3字段) 1 是 否 2 是 否 2 否 是 3 否 是select case when max(case when a = '是' then 1 else 0 end)=1 then '是' else '否' end a, case when max(case when b = '是' then 1 else 0 end)=1 then '是' else '否' end b from scott.A group by id等待好的解决方式啊
select id, max(b),max(c) from a group by id
from A a
group by a.id;这样可以吗?嘿嘿
select a.id,sum(decode(a.b,'是',1,0)),sum(decode(a.c,'是',1,0))
from A a
group by a.id;
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;
ID b c (3字段)
1 是 否
2 是 否
2 否 是
3 否 是select case when max(case when a = '是' then 1 else 0 end)=1 then '是' else '否' end a,
case when max(case when b = '是' then 1 else 0 end)=1 then '是' else '否' end b
from scott.A
group by id等待好的解决方式啊
select id , sum(b) as B , sumc(c) as C
from A group by id