Prepare > SQL > Alternative Queries > Draw The Triangle 2

2023. 6. 12. 19:53HackerRank-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