SQL 4 Oracle 오라클용 sql 실무

SQL4Oracle

COUNT 방법 (중복배제 집계, NULL 집계, 부분 집계)

돌프1 2023. 3. 10. 13:32

2011-08-02 11:07:30


SQL 4 Oracle 오라클용 sql 실무
▒ COUNT 방법 (중복배제 집계,  NULL 집계, 부분 집계)

 

select 고객구분, 취득지역, 취득종류,
     count(DISTINCT 고객ID) 고객수 ,count(*) 건수 ,
     sum( case when 전화번호    is not null   then 1 else 0 end) 전화있는건수,
     sum( case when 휴대폰번호 is not null   then 1 else 0 end) 휴대폰있는건수,
     sum( case when 전화번호    is not null or   휴대폰번호 is not null then 1 else 0 end) 둘중하나이상_있는건수,   
     sum( case when 전화번호    is not null and 휴대폰번호 is not null then 1 else 0 end) 전화_휴대폰_둘다있는건수 ,
     sum( case when 전화번호    is null      and 휴대폰번호 is null      then 1 else 0 end) 전화_휴대폰_둘다없는건수 
from
(    
  select 
      고객ID, 고객명, 고객구분, 취득지역, 취득종류, 전화번호, 휴대폰번호
   from 목적_Table
  where 고객상태='활동중'
)
group by 고객구분, 취득지역, 취득종류

 

'SQL4Oracle' 카테고리의 다른 글

기본 힌트  (0) 2023.03.10
줄바꿈관련 특수문자 제거  (0) 2023.03.10
PLSQL 10초마다 무한반복  (0) 2023.03.10
우편번호로 시군구 지역 고객찾기  (0) 2023.03.10
replace  (0) 2023.03.10