본문 바로가기

Oracle/SQL Question

[퀴즈] 집약함수

문제>
다음과 같이 데이터 가 있다고 가정하자.
with tour_group as
(
    select '111' tour_key, '중국관광단' tour_title, '중국' tour_position, '2011.01.03' start_day, '2011.01.13' end_day
    from dual union all
    select '222', '일본광광단', '일본', '2011.01.05', '2011.01.11' from dual
),
tour_person as
(
    select '111' tour_key, 1 tour_seq, '백두산' tour_person_name from dual union all
    select '111', 2, '한라산' from dual union all
    select '111', 3, '금강산' from dual union all
    select '222', 1, '김대리' from dual union all
    select '222', 2, '박과장' from dual union all
    select '222', 3, '최과장' from dual union all
    select '222', 4, '권차장' from dual union all
    select '222', 5, '신부장' from dual
)
select *
from tour_group   a,
        tour_person b
where a.tour_key=b.tour_key;

결과 >


위에 처럼 나오는 데이터를 아래와 같이 바꿔보자.
같은 여행상품인경우 NAME에 여행자이름이 한행에 다 나오도록 해보자.

정답 트리플클릭>
select a.tour_title,a.tour_position,a.start_day,a.end_day,wm_concat(tour_person_name) name
from tour_group a,tour_person b
where a.tour_key=b.tour_key
group by a.tour_title,a.tour_position,a.start_day,a.end_day;