Re: sql select question
- From: "ChrisH" <chris.hulan@xxxxxxxxx>
- Date: 25 Apr 2006 11:31:48 -0700
hilz wrote:
Hi all
this is more of an SQL question than a Java question.
I have a table with a SPEED column and some other columns like this:
SPEED SOME_OTHER_COLUMNS....
----- ------------------
100 some values here...
34
97
68
13
27
44
now I want to select the two rows that surround a value I am interested
in. For example, if I am interested in a value of 55, I want to select
the two rows that have a speed of 44 and 68.
Is there a way of doing that in SQL ?
i can handle the case where i get an exact match separately.
I just need to know how to select exactly two rows (the one above the
given value and the one below it).
Thanks for any help.
select *
from aTable
where speed = (select max(speed) from aTable where speed < 55)
or speed = (select min(speed) from aTable where speed > 55)
.
- Follow-Ups:
- Re: sql select question
- From: hilz
- Re: sql select question
- From: hilz
- Re: sql select question
- References:
- sql select question
- From: hilz
- sql select question
- Prev by Date: sql select question
- Next by Date: Re: sql select question
- Previous by thread: sql select question
- Next by thread: Re: sql select question
- Index(es):
Relevant Pages
|
|