Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
User Journal

Chacham's Journal: Verbiage: Solve AH + A = HEE in SQL 10

Journal by Chacham

Solve AH + A = HEE (where each letter is representative of a distinct number). Easy enough? Now do it in SQL. Yes, this post is insane, but short and elegant.

SELECT H.n||E.n||E.n as H_E_E
FROM
(SELECT LEVEL-1 n FROM DUAL CONNECT BY LEVEL <=10) A,
(SELECT LEVEL-1 n FROM DUAL CONNECT BY LEVEL <=10) H,
(SELECT LEVEL-1 n FROM DUAL CONNECT BY LEVEL <=10) E
WHERE A.n NOT IN (H.n, E.n)
AND H.n NOT IN (A.n, E.n)
AND E.n NOT IN (A.n, H.n)
AND mod(H.n + A.n - E.n, 10) = 0
AND mod(A.n + trunc((H.n + A.n - E.n)/10)- E.n, 10) = 0
AND trunc((A.n + trunc((H.n + A.n - E.n)/10) - E.n)/10) = H.n

This discussion has been archived. No new comments can be posted.

Verbiage: Solve AH + A = HEE in SQL

Comments Filter:
  • What would you like it to be?
    • by Chacham (981)
      What would you like it to be?

      There's a sign here that perhaps answers that question.

      IIRC, part of it states something like:

      Please do not brush your teeth here

      This is the kitchen

      IT is very unhygienic for everyone

      So, to answer your question, i want IT to be hygienic for everyone.

  • Either that, or I'm doing it wrong. I get the following error message:
    ERROR: syntax error at or near "n" at character 52
    LINE 3: (SELECT LEVEL-1 n FROM DUAL CONNECT BY LEVEL
    • by Chacham (981)
      It may not like fake hierarchical queries. Perhaps SELECTing from a TABLE with ten records will do the job?

      In Oracle, a similar construct would be SELECT Rownum -1 FROM User_Objects WHERE Rownum 11;
    • Uhhh...isn't CONNECT BY an Oracle-specific extension to Stupid Question Language?
      • I know nothing about CONNECT BY nor Oracle, so it makes sense...
        That was one reason I tried his statement, because I thought I'd learn something from it. I suppose I have!
      • by Chacham (981)
        isn't CONNECT BY an Oracle-specific extension

        Yes. In ANSI a recursive WITH could be used.

        to Stupid Question Language?

        Not sure why you are mocking Oracle on this. After all,Relational Software, Inc. (now Oracle Corporartion) was the first commercial implementation of SQL (1979) well before there was a standard.
        • Wasn't mocking Oracle at all. I refer to SQL as "Squeal" or "Stupid Question Language" in conversation.
          Truly, I respect the functional style of programming embodied thereby, even though most of the work I do involves Microsoft Abcess.

Old programmers never die, they just branch to a new address.

Working...