Oracle

게시글 보기
작성자 유건데이타 등록일 2015-05-20
제목 해당 TABLE에 DATA가 없는 값도 COUNT 하는 방법
해당 TABLE에 DATA가 없는 값도 COUNT 하는 방법
============================================

Explanation
-----------
만일, code 값으로 n,y를 가진 code table이 있고 test table에서 모든 code 값과 count를 계산하는 방법은 다음과 같다.

Example
-------
SQL> desc code
Name Null? Type
------------------------------- -------- ----
CODE1 VARCHAR2(2)


SQL> select * from code;

CO
--
y
n

SQL> desc test
Name Null? Type
------------------------------- -------- ----
CODE VARCHAR2(2)
VALUE VARCHAR2(5)

SQL> select * from test;

CO VALUE
-- -----
y q
y t

select count(*), code from test group by code
union all
select cnt, c1
from (select count(code) cnt from test where code not in (select code1 from code)),(select code1 c1 from code where code1 not in (select code from test))
Comment
등록된 코멘트가 없습니다.