Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: SQL Fun Challenge #2
Here is one solution. Note that table population with numbers is
optional, the same effect can be achieved by using a large number of
"select 1 from dual union select 2 from dual ...". Note also that the
upper limit is also arbitrary as long as it is large enough (perhaps
upto the age of the father minus 18 or so; assuming he got married
then.)
Finally, for extra credit, the result returns the ages in increasing
order, i.e., from youngest to eldest:
STEP 1) CREATE TABLE ages (age NUMBWER);
STEP 2) INSERT INTO ages VALUES (1);
...
INSERT INTO ages VALUES (36);
COMMIT;
STEP 3) select a1, a2, a3
from
(
select c1.age a1, c2.age a2, c3.age a3, c1.age + c2.age + c3.age
totals
from ages c1, ages c2, ages c3
where
c1.age * c2.age * c3.age = 36 and c1.age <= c2.age and c2.age <= c3.age
c1.age * c2.age * c3.age = 36 and c1.age <= c2.age and c2.age <= c3.age and c1.age + c2.age + c3.age = t1.totals
and a3 > a1 and a3 > a2
Daniel Morgan <damorgan_at_x.washington.edu> wrote in message news:<1078359740.735908_at_yasure>...
> Two mathematicians (Boris and Vladimir) met accidently for the first
> time in 20 years.
>
> They greet each other and begin catching up on their respective lives.
>
> Boris asks Vladi
> "Do you have any children?" "Yes" replies Vladimir, "I have three." "How
> old are they?", asks Boris.
>
> "The product of their ages is 36 and the sum of their ages is equal to
> the number of windows on that building across the street." Boris looks
> at the building, counts the windows then says "Vladi, that still doesn't
> tell me the ages." "Ah, says Vladi, then I must tell you that the eldest
> has red hair." "Oh", says Boris, "now I know their ages." What are the
> ages of Boris' children?
>
>
> Create a table, load it with data, and write a single SQL statement to
> produce the data set required to deduce the answer ... then deduce away!
Received on Thu Mar 04 2004 - 02:11:50 CST