Hi all,
version : Oracle 11gr2/12c
Note : This thread is just meant to understand different ways in SQL for solving this simple puzzle.. And more towards getting inputs from you all to see how you all think differently in these scenarios. Hope to get +ve responses.
If you are trying to attempt this thread please make sure the method is not mentioned anywhere in the thread, this way it would be easy to find distinct ways to solve.
Fastest solution would be noted in my personal notes and would be used for my learning.
Thanks!
Puzzle : find XYZ

solution which I thought was as below.. any other ways (possibly recursion or model etc....):
==========
WITH dataset
AS ( SELECT ROWNUM + 99 num,
SUBSTR (ROWNUM + 99, 1, 1) r1,
SUBSTR (ROWNUM + 99, 2, 1) r2,
SUBSTR (ROWNUM + 99, 3, 1) r3
FROM DUAL
CONNECT BY ROWNUM \<= 999)
SELECT num,
r1 \* 11 col1,
r2 \* 11 col2,
r3 \* 11 col3
FROM dataset
WHERE (r1 * 11) + (r2 * 11) + (r3 * 11) = num;
Please post your versions.
Cheers,
Manik.