This article is half-done without your Comment! *** Please share your thoughts via Comment ***
Check the below input data and expected output to get the power of three within first 100 numbers.
Expected Output:
1 2 3 4 5 6 7 |
PowerOfThree ------------ 1 3 9 27 81 |
Create a table with first 100 numbers:
1 2 3 4 5 6 7 8 9 10 11 12 |
CREATE TABLE tbl_Numbers ( ID INT ); DECLARE @Counter AS INT = 1; BEGIN WHILE @Counter < 100 BEGIN INSERT INTO tbl_Numbers VALUES (@Counter); SET @Counter = @Counter + 1; END; END; |
Solution:
1 2 3 |
SELECT ID AS PowerOfThree FROM tbl_Numbers WHERE LOG(ID, 3) = ROUND( LOG(ID, 3), 0); |
Please try the different solution for this puzzle and share it via comment...