Member-only story

Draw The Triangle 1 — Advanced SQL — HackerRank SQL

Amber Ivanna Trujillo
2 min readOct 21, 2020

--

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).

Solution

Solution for MY SQL Server

DECLARE @var int               -- Declare SELECT @var = 20                -- Initialization WHILE @var > 0                 -- condition 
BEGIN -- Begin
PRINT replicate('* ', @var) -- Print
SET @var = @var - 1 -- decrement
END

Output

* * * * * * * * * * * * * * * * * * * * 
* * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * *
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*

--

--

Amber Ivanna Trujillo
Amber Ivanna Trujillo

Written by Amber Ivanna Trujillo

I am Executive Data Science Manager. Interested in Deep Learning, LLM, Startup, AI-Influencer, Technical stuff, Interviews and much more!!!

No responses yet