Created
December 25, 2024 18:47
-
-
Save Animesh-Ghosh/eab3d46ebadacc871f1a5674b58c9f6d to your computer and use it in GitHub Desktop.
Christmas Tree in SQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- original version found on @iavins Tweet: https://x.com/iavins/status/1871914543590289672 | |
| WITH RECURSIVE numbers(n) AS ( | |
| SELECT 1 | |
| UNION ALL | |
| SELECT n + 1 FROM numbers WHERE n < 9 | |
| ), tree_parts(level, stars, spaces) AS ( | |
| SELECT | |
| n, | |
| REPEAT('*', n * 2 - 1), | |
| REPEAT(' ', 20 - n) | |
| FROM numbers | |
| ), trunk(level, stars, spaces) AS ( | |
| SELECT 10, '|||', REPEAT(' ', 18) | |
| UNION ALL | |
| SELECT 11, '|||', REPEAT(' ', 18) | |
| ) | |
| SELECT level, spaces || stars AS tree FROM tree_parts | |
| UNION ALL | |
| SELECT level, spaces || stars FROM trunk; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment