그룹 통계 조회

create table tb
(
id int,
   varchar(50),
   int,
   int,
  ID int

)
 
insert into tb values(1,'A',1,1,1111)
insert into tb values(2,'B',1,0,3333)
insert into tb values(3,'C',2,0,3333)
insert into tb values(4,'D',3,0,3333)
insert into tb values(5,'E',3,0,4444)
insert into tb values(6,'F',3,0,4444)

 

 
 
SELECT   ID,

       sum(case when    = 1 and    = 0 then 1 else 0 end) [  1  0   ],
       sum(case when    = 1 and    = 1 then 1 else 0 end) [  1  1   ],
       sum(case when    = 2 and    = 0 then 1 else 0 end) [  2  0   ],
       sum(case when    = 2 and    = 1 then 1 else 0 end) [  2  1   ],
       sum(case when    = 3 and    = 0 then 1 else 0 end) [  3  0   ],
       sum(case when    = 3 and    = 1 then 1 else 0 end) [  3  1   ]
from tb
group by   ID

SELECT   ID,


from tb
group by   ID

좋은 웹페이지 즐겨찾기