
Problem
P(R) represents a pattern drawn by Julia in R rows. The following pattern represents P(5):
*
* *
* * *
* * * *
* * * * *
Write a query to print the pattern P(20).
Analysis
For this problem, use REPEAT function to generate texts of each line. Also, use a variable to decide the length of each line and apply REPEAT functon for each row of a table with at least 20 rows. Finally, control the number of lines to output.
First, declare and initialize a variable:
|
|
Then, choose a table with at least 20 rows and apply REPEAT function for each row. Also, increase the variable by 1 each time before applying the function:
|
|
Finally, output the first 20 lines:
|
|
Or
|
|
Solution
Solution 1
|
|
Solution 2
|
|
Link
Draw The Triangle 2
(中文版) SQL 笔记: Hackerrank Draw The Triangle 2




近期评论