Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Alternate ways to solve this simple puzzle

ManikAug 24 2017 — edited Aug 25 2017

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

pastedImage_0.png

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.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 22 2017
Added on Aug 24 2017
27 comments
1,273 views