본문 바로가기

Study/class note

문제3. SQL / class_type, 통신사, 인원수를 출력하기

[내가 쓴 코드] 

select class_type, 통신사, count(*)
 from (select class_type, decode(lower(telecom), 'skt','sk',lower(telecom)) as 통신사
        from emp14)
  group by rollup( class_type, 통신사);

 

[다른 사람이 쓴 코드]

--1
select class_type, decode(lower(telecom),'skt','sk',lower(telecom)), count(*)
 from emp14
 group by rollup ( class_type, decode(lower(telecom),'skt','sk',lower(telecom)));

--2
create or replace view emp14_telecom
as
select class_type, decode(upper(telecom),'SK','SKT',upper(telecom)) as telecom2
    from emp14;

select class_type, telecom2, count(*)
    from emp14_telecom 
    group by rollup(class_type, telecom2);

 

[해결]

  1. 내가 쓴 코드는 서브쿼리, 다른 사람이 쓴 코드2는 view를 이용했음 > decode 함수를 늘리지 않는 방식

 

[유의할점]

  1. 일반쿼리, 서브쿼리, view 등 어떤 식을 적절하게 써야하는지 생각해보기
  2. 컬럼별칭 설정 시 영어 권장
반응형