SQL 기초 실무/SQL 알고리즘 문제

23.09.29. SQL Developer 알고리즘 문제 ④

잇꼬 2023. 10. 4. 10:58
728x90
반응형
SMALL

4. 삼각형을 SQL로 출력하기

-- 예제 114. 삼각형을 SQL로 출력하기.
select lpad(' ', 10-level, ' ') 
    from dual 
    connect by level <= 8 ;

select lpad('★', level, '★') 
    from dual 
    connect by level <= 8 ;
    
with loop_table as ( select level as num
                                    from dual 
                                    connect by level <= 8 ) 
select lpad(' ', 10-num, ' ' ) || lpad('★', num, '★') as "Triangle"
    from loop_table ;
    
-- 문제1. 아래와 같이 역삼각형을 출력하세요.

with loop_table as ( select level as num
                                    from dual 
                                    connect by level <= 8 ) 
select lpad(' ', num, ' ' ) || lpad('★', 9-num, '★') as "Triangle"
    from loop_table ;
728x90
반응형
LIST