본문 바로가기

SQL/[HackerRank]

[HackerRank/MySQL] Draw The Triangle 2

728x90

< Problem >

삼각형 그리기

링크:  https://www.hackerrank.com/challenges/draw-the-triangle-2/problem

 

Draw The Triangle 2 | HackerRank

Draw the triangle pattern using asterisks.

www.hackerrank.com


< Code >

SET @n = 0;
SELECT REPEAT('* ', @n := @n + 1)
FROM information_schema.tables
LIMIT 20

 

< Lesson & Learned >

SET @a=b: 변수a를 선언하고 값b를 할당.
SELECT
: 키워드와 함께 검색하고 싶은 속성의 이름을 나열
REPEAT(문자열, n): 문자열을 n번 반복해 출력함.
FROM: 키워드와 함께 검색하고 싶은 속성이 있는 데이블의 이름을 나열

LIMIT a: 첫번째 행에서부터 a개 데이터를 가져옴.

728x90