Prepare > SQL > Alternative Queries > Draw The Triangle 2
2023. 6. 12. 19:53ㆍHackerRank-My SQL
Draw The Triangle 2 | HackerRank
Draw the triangle pattern using asterisks.
www.hackerrank.com
문제
The following pattern represents P(5):
*
* *
* * *
* * * *
* * * * *
Write a query to print the pattern P(20).
코드
WITH RECURSIVE root AS (
SELECT 20 AS K
UNION ALL
SELECT K-1 FROM root
WHERE K>1
)
SELECT REPEAT("* ", K) AS W FROM root
ORDER BY W ASC;
노트
SET @COUNT = 0;
SELECT REPEAT('* ', @COUNT := @COUNT+1)
FROM INFORMATION_SCHEMA.TABLES
LIMIT 20;
참조
Prepare > SQL > Alternative Queries > Draw The Triangle 1
Draw The Triangle 1 | HackerRank Draw the triangle pattern using asterisks. www.hackerrank.com 문제 The following pattern represents P(5): * * * * * * * * * * * * * * * Write a query to print the pattern P(20). 코드 SET @NUMBER = 21; SELECT REPEAT('* '
my-little-diary.tistory.com
'HackerRank-My SQL' 카테고리의 다른 글
Prepare > SQL > Advanced Select > Occupations (0) | 2023.06.14 |
---|---|
Prepare > SQL > Aggregation > Weather Observation Station 20 (0) | 2023.06.14 |
Prepare > SQL > Alternative Queries > Draw The Triangle 1 (0) | 2023.06.11 |
Prepare > SQL > Advanced Join > Interviews (0) | 2023.06.08 |
Prepare > SQL > Advanced Join > Symmetric Pairs (0) | 2023.06.06 |