A表 ID  b  c  (3字段)
1   1  0
2   1  0 
2   0  1
3   0  1用一语句合并结果为
ID  B   C1   1   0
2   1   1
3   0   1 所有写0的地方可以不写,要求就是sqlserver和oracle都可以用,简单明了,help~~~~

解决方案 »

  1.   

    如果数据就是你给的例子的数据,可以这样写
    select id, max(b),max(c) from a group by id
      

  2.   

    select a.id,sum(a.b),sum(a.c)
      from A a
     group by a.id;这样可以吗?嘿嘿
      

  3.   

    如果sum的话你可以使用decode
    select a.id,sum(decode(a.b,'是',1,0)),sum(decode(a.c,'是',1,0))
    from A a
    group by a.id;
      

  4.   

    用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;
      

  5.   

    回 hongqi162(失踪的月亮)  那个decode在sqlserver 里应该是不能用
      

  6.   

    在sqlserver里用sum(case when '是' then 1 else 0 end)
      

  7.   

    恩我是不想再在sqlserver里换语句了,头痛,呵呵
      

  8.   

    在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等待好的解决方式啊
      

  9.   

    我是这样理解,mantisXF(枫の叶) 里说了max可以max字符,那用 bobfang(匆匆过客) 的就可以了,把表里的1改成'是'一样可以用了
      

  10.   

    最简单的
    select id , sum(b) as B , sumc(c) as C
    from A group by id