_대문 | 방명록 | 최근글 | 홈피소개 | 주인놈
FrontPage › 막대그래프

응용 예제3 #

이 문제는 sqler.pe.kr에서 발견한 문제([http]여기)입니다. 링크로 가보면 문제가 두 개인데 비슷한 방식으로 푸는 문제입니다. 재미있을꺼 같아 한 개만 풀어봤습니다. (원리만 이해한다면 트래이닝 건덕지도 아니지요.)

원하는 결과

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

댓글 남기기..
이름: : 오른쪽의 새로고침을 클릭해 주세요. 새로고침
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2018-04-13 23:12:53

어떤 말을 만번 이상 되풀이 하면 반드시 미래에 그 일이 이루어진다. (아메리카 인디언 금언)