Beta

Slashdot: News for Nerds

×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Verbiage: Solve AH + A = HEE in SQL

Chacham (981) writes | more than 6 years ago

User Journal 10

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.

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

cancel ×

10 comments

An Accountant's Answer (1)

Shadow Wrought (586631) | more than 6 years ago | (#21586105)

What would you like it to be?

Re:An Accountant's Answer (1)

Chacham (981) | more than 6 years ago | (#21586383)

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.

Doesn't work in postgresql (1)

benhocking (724439) | more than 6 years ago | (#21586241)

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

Re:Doesn't work in postgresql (1)

Chacham (981) | more than 6 years ago | (#21586661)

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;

Meta-stupid question (1)

smitty_one_each (243267) | more than 6 years ago | (#21586915)

Uhhh...isn't CONNECT BY an Oracle-specific extension to Stupid Question Language?

If you say so (1)

benhocking (724439) | more than 6 years ago | (#21587231)

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!

Re:Meta-stupid question (1)

Chacham (981) | more than 6 years ago | (#21588341)

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.

Re:Meta-stupid question (1)

smitty_one_each (243267) | more than 6 years ago | (#21588769)

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.

Re:Meta-stupid question (1)

Chacham (981) | more than 6 years ago | (#21593033)

Ah, OK then.

I seem to be taking everything the wrong way today. :)

Re:Meta-stupid question (1)

smitty_one_each (243267) | more than 6 years ago | (#21595757)

I will pause for a moment to admire the commitment to minimalism embodied in http://tkatch.com/ [tkatch.com]
Check for New Comments
Slashdot Account

Need an Account?

Forgot your password?

Don't worry, we never post anything without your permission.

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>
Create a Slashdot Account

Loading...