Home » SQL & PL/SQL » SQL & PL/SQL » calculate threshold value
calculate threshold value [message #217780] Mon, 05 February 2007 08:01 Go to next message
steffeli
Messages: 112
Registered: July 2006
Senior Member
Hello

How can I calculate the average of the highest value in Quantil 4 and the lowest value in Quantil 5 (I have 8 Quantils all together)? My table TAB looks like this:

ID   QUANTIL    VALUE
1    1          2.45
2    1          2.98
...
49   4          3.05
50   5          3.59
...
99   8          3.89
100  8          3.98



The result should be = (3.05 + 3.59)/2 = 3.32

Thanks for your help!
Stefan

[Updated on: Mon, 05 February 2007 08:02]

Report message to a moderator

Re: calculate threshold value [message #217784 is a reply to message #217780] Mon, 05 February 2007 08:44 Go to previous message
srinivnp
Messages: 136
Registered: January 2006
Location: stlouis MO USA
Senior Member

SQL> select * from foo;

ID QTL VAL
---------- ---------- ----------
1 1 2.45
2 1 2.98
49 4 3.05
50 5 3.59
99 8 3.89
100 8 3.98

6 rows selected.







Quote:
select sum(case when qtl=4 then mx
when qtl=5 then mn
else 0 end )/2 as reqavg
from (
select max(val) mx , min(val) mn , qtl
from foo where qtl in (4,5)
group by qtl
)
SQL> /

REQAVG
----------
3.32


Srini


Previous Topic: what are database servers
Next Topic: How to create a Column that will "carry over" values
Goto Forum:
  


Current Time: Sat Dec 03 04:13:23 CST 2016

Total time taken to generate the page: 0.21666 seconds