#title 막대그래프 ==== 응용 예제3 ==== 이 문제는 sqler.pe.kr에서 발견한 문제([http://sqler.pe.kr/web_board/view_list.asp?id=1218&read=149&pagec=1&gotopage=1&block=0&part=myboard7&tip=ok 여기])입니다. 링크로 가보면 문제가 두 개인데 비슷한 방식으로 푸는 문제입니다. 재미있을꺼 같아 한 개만 풀어봤습니다. (원리만 이해한다면 트래이닝 건덕지도 아니지요.) {{{ 원하는 결과 num a b c d e ----------- ---- ---- ---- ---- ---- 5 ▒ 4 ▒ 3 ▒ ▒ 2 ▒ ▒ ▒ 1 ▒ ▒ ▒ ▒ 0 ▒ ▒ ▒ ▒ ▒ NULL 1 3 5 0 2 }}} {{{ --쿼리 결과는 텍스트로 보고 고정길이 폰트(~~체)로 보면 된다. 옵션 바꾸는거 귀찮으면 메모장으로 복사해서 보면 된다. with temp(num) as ( select 6 numm union all select num - 1 from temp where num - 1 >= 0 ), val(a,b,c,d,e) as ( select '1' a, '3' b, '5' c, '0' d, '2' e ) select case when b.num = 0 then null else b.num - 1 end num , case when b.num = 0 then a when b.num - 1 <= a.a then '▒' else '' end a , case when b.num = 0 then b when b.num - 1 <= a.b then '▒' else '' end b , case when b.num = 0 then c when b.num - 1 <= a.c then '▒' else '' end c , case when b.num = 0 then d when b.num - 1 <= a.d then '▒' else '' end d , case when b.num = 0 then e when b.num - 1 <= a.e then '▒' else '' end e from val a cross join temp b }}}