Getting MAx value runtime [message #246089] |
Tue, 19 June 2007 21:15 |
rawat_me
Messages: 45 Registered: September 2005
|
Member |
|
|
Hi,
My requirement is that i have to get the MAX or Greatest of the three values from three tables and replace each value with the Hightest value.
Example :
select
age2 = c.age - b.age,
age3 = a.age - b.age,
age1 = a.age
from a , b , c
where a.name = b.name
and a.deptid = c.deptid
Now my requirement is that to check which age is greatest ( heightest ) among age1 , age2 , age3 and then assign each age i.e. age1 , age2 and age3 with that heightest age.
I have to do it in SQL only . No pl/sql please
Regards
Rawat
|
|
|
|
Re: Getting MAx value runtime [message #246272 is a reply to message #246103] |
Wed, 20 June 2007 08:22 |
rawat_me
Messages: 45 Registered: September 2005
|
Member |
|
|
Hi Michel,
I have done it By nested Case statement :
select
Case
when ( c.age - b.age ) > ( a.age - b.age )
then
case
when ( c.age - b.age ) > a.age
then ( c.age - b.age )
else
a.age
end
else
when ( a.age - b.age ) > a.age
then
case
when ( a.age - b.age ) > a.age
then
( a.age - b.age )
else
a.age
end
end age3,
Case
when ( c.age - b.age ) > ( a.age - b.age )
then
case
when ( c.age - b.age ) > a.age
then ( c.age - b.age )
else
a.age
end
else
when ( a.age - b.age ) > a.age
then
case
when ( a.age - b.age ) > a.age
then
( a.age - b.age )
else
a.age
end
end age2,
Case
when ( c.age - b.age ) > ( a.age - b.age )
then
case
when ( c.age - b.age ) > a.age
then ( c.age - b.age )
else
a.age
end
else
when ( a.age - b.age ) > a.age
then
case
when ( a.age - b.age ) > a.age
then
( a.age - b.age )
else
a.age
end
end age1
from a , b , c
where a.name = b.name
and a.deptid = c.deptid
It worked.
Thanks for ur suggestion.
Rawat
|
|
|
|
|