一道小學題的sql實現~~~

junsansi發表於2008-01-23

5位數乘一位數,其結果是此5位數中數字倒序所形成的新五位數.即:ABCDE*F=EDCBA
其中a<>b<>c<>d<>e<>f

實現如下:

SQL> with tt as(select level lv from dual connect by level < 10)
  2  select a.lv || b.lv || c.lv || d.lv || e.lv || '*' || f.lv expr,
  3         e.lv || d.lv || c.lv || b.lv || a.lv result
  4    from tt a, tt b, tt c, tt d, tt e, tt f
  5   where to_number(a.lv || b.lv || c.lv || d.lv || e.lv) * f.lv =
  6         to_number(e.lv || d.lv || c.lv || b.lv || a.lv)
  7     and a.lv <> b.lv
  8     and a.lv <> c.lv
  9     and a.lv <> d.lv
 10     and a.lv <> e.lv
 11     and a.lv <> f.lv
 12  /
 
EXPR                                                                             RESULT
------------------------- -------------------------------
21978*4                                                                          87912
 
SQL>

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7607759/viewspace-157790/,如需轉載,請註明出處,否則將追究法律責任。

相關文章