select a.party winparty, count(*) GetSeat from
(select distinct party, small_district, gain from election where SubStr(big_district, 2,1) = 2) a,
(select small_district, max(gain) max_gain from election group by small_district) b
where a.small_district = b.small_district and a.gain = b.max_gain
group by party
위의 쿼리문에서 결과가 winparty로 표현되는데요..
이 winparty가 [1..5]값으로 표현되게 되어있습니다..
이걸 새로운 테이블에 party명이 넣어진 새로운 테이블을 이용해(아래 내용) 표현하려면 어떻게 해야하나요?
1 : aaa
2 : bbb
3 : ccc
4 : ddd
5 : eee
이렇게 숫자가 아닌 이름으로 바꿔주고 싶은데요..
쿼리문에서 다른 추가 문장이 들어가야 하나요?
알려주시어여..
> select a.party winparty, count(*) GetSeat from
> (select distinct party, small_district, gain from election where SubStr(big_district, 2,1) = 2) a,
> (select small_district, max(gain) max_gain from election group by small_district) b
> where a.small_district = b.small_district and a.gain = b.max_gain
> group by party
>
> 위의 쿼리문에서 결과가 winparty로 표현되는데요..
> 이 winparty가 [1..5]값으로 표현되게 되어있습니다..
> 이걸 새로운 테이블에 party명이 넣어진 새로운 테이블을 이용해(아래 내용) 표현하려면 어떻게 해야하나요?
>
> 1 : aaa
> 2 : bbb
> 3 : ccc
> 4 : ddd
> 5 : eee
>
> 이렇게 숫자가 아닌 이름으로 바꿔주고 싶은데요..
> 쿼리문에서 다른 추가 문장이 들어가야 하나요?
> 알려주시어여..
>
질문의 의도를 잘 파악했는지 모르겠는데여.....
새로운 테이블에
------------------------
winparty wp_name
------------------------
1 aaa
2 bbb
3 ccc
4 ddd
5 eee
------------------------
이렇게 들어가있고 현재 쿼리에서 나오는 '1' 대신 'aaa'를 넣고 싶다는
얘기인 듯하고 그렇다는 가정하에 답변하겠습니다.
Query 문을 거의 안고치고 하자면....
새로운 Table을 Tab_new 라고 가정할 때...
select New.wp_name , Old.GetSeat from Tab_new New,
(
select a.party winparty, count(*) GetSeat from
(select distinct party, small_district, gain from election
where SubStr(big_district, 2,1) = 2) a,
(select small_district, max(gain) max_gain from election
group by small_district) b
where a.small_district = b.small_district and a.gain = b.max_gain
group by party
) Old
where New.winparty = Old.winparty
-- 이렇게 하면 될겁니다. 물론 가장 기존의 쿼리를 안건드린 방법이구여..
각종 여러가지 방법이 있겠지요....근데....질문의 의도에는 맞는지....
암튼 잘 되시길 빕니다.