2011-08-18 12:53:35
SQL 4 Oracle 오라클용 sql 실무
▒ 회차 구간별 집계
회차: 시작일부터 1회차,다음일부터 2회차
▒ 취득 회차 구간별 집계
select
(case
when trunct( months_between( sysdate , 취득일자 )) + 1 <= 1 then '1회차'
when trunct( months_between( sysdate , 취득일자 )) + 1 <= 2 then '2회차'
when trunct( months_between( sysdate , 취득일자 )) + 1 <= 3 then '3회차'
when trunct( months_between( sysdate , 취득일자 )) + 1 > 3 then '3회차초과'
else '0'
end) 회차구간,
,sum(점수) 합계점수
,count(distinct 고객ID) 고객수
,count(*) 건수
from 목적_Table bm
where 고객상태='활동중'
group by
(case
when trunct( months_between( sysdate , 취득일자 )) + 1 <= 1 then '1회차'
when trunct( months_between( sysdate , 취득일자 )) + 1 <= 2 then '2회차'
when trunct( months_between( sysdate , 취득일자 )) + 1 <= 3 then '3회차'
when trunct( months_between( sysdate , 취득일자 )) + 1 > 3 then '3회차초과'
else '0'
end)

'SQL4Oracle' 카테고리의 다른 글
| 재미있는 DUAL 테이블2 (0) | 2023.03.10 |
|---|---|
| 재미있는 DUAL 테이블 (0) | 2023.03.10 |
| Informix와 Oracle 달랐던 점 한가지 (0) | 2023.03.10 |
| 주민등록번호 성별 구분 (0) | 2023.03.10 |
| Sub Query (0) | 2023.03.10 |