We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Draw The Triangle 1
Draw The Triangle 1
Sort by
recency
|
1249 Discussions
|
Please Login in order to post a comment
For Mysql using the RECURSIVE statement:
WITH RECURSIVE cnt (n) AS ( SELECT 20 UNION ALL SELECT n - 1 FROM cnt WHERE n > 1 ) SELECT REPEAT("* ", n) FROM cnt;
MS SQL Server
WITH RECURSIVE Patterns(n) as( Select cast('' as char(255)) UNION ALL Select concat(n, '') from Patterns where length(n) < 20
) select * from Patterns ORDER BY length(n) DESC; Please Whats wrong with my code. It prints out the *.
MS SQL - This code works; DECLARE @n INT = 20; DECLARE @i INT = 20; DECLARE @p VARCHAR(100) = '';
WHILE @i <= @n AND @i>0 BEGIN DECLARE @j INT = 1; SET @p = '' WHILE @j<=@i BEGIN SET @p = @p + '* '; SET @j = @j + 1; END PRINT @p; SET @i = @i - 1; END