Draw The Triangle 2 in SQL | HackerRank Solution

Hello coders, today we are going to solve Draw The Triangle 2 HackerRank Solution in SQL.

Draw The Triangle 2

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

Solution – Draw The Triangle 2 in SQL

MySQL

set @row := 0;
select repeat('* ', @row := @row + 1) from information_schema.tables where @row < 20

Disclaimer: The above Problem (Draw The Triangle 2) is generated by Hacker Rank but the Solution is Provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.

1 thought on “Draw The Triangle 2 in SQL | HackerRank Solution”

  1. DECLARE @row int
    SELECT @row = 1
    WHILE @row < 21
    BEGIN
    PRINT replicate('* ', @row)
    SET @row = @row + 1
    END

    OR

    DECLARE @row int = 1
    WHILE @row < 21
    BEGIN
    PRINT replicate('* ', @row)
    SET @row = @row + 1
    END

Leave a Comment

Your email address will not be published. Required fields are marked *