select id,sum(case 条件=1 then 1 else 0 end),sum(case 条件<>1 then 1 else 0 end) from table group by id

解决方案 »

  1.   

    select id,
    sum(case when dd='1' then 1 else 0 end)as 是1的总数,
    sum(case when dd<>'1' then 1 else 0 end)as 不是1的总数
    from tbname
    group by id
      

  2.   

    Select D.id,D.yes,D.no from(
    SELECT C.id,A.YES,B.NO FROM Table C,
    (select count(*) as yes from table where id='A00001') A,
    (select count(*) as no from talble where id<>'A00001') B
    ) D
      

  3.   

    select id,sum(case when........end),sum(case when ......end)from table group by id