Re: sql select question
- From: "ChrisH" <chris.hulan@xxxxxxxxx>
- Date: 28 Apr 2006 07:45:34 -0700
hilz wrote:
....
Ok... my situation got a little more complecated now. I hope it is still.....
doable with one sql select
Hi, I almost gave up on this one 9^) but finally have a solution.
However, its ugly (IMHO) and I cannot guarantee it works in all cases.
Here it is:
SELECT *
FROM (SELECT *
FROM chtmp
WHERE (( speed = (SELECT MAX (speed)
FROM chtmp
WHERE speed < 35)
OR speed = (SELECT MIN (speed)
FROM chtmp
WHERE speed > 35)
)
)) spd
WHERE ( spd.distance = (SELECT MAX (distance)
FROM chtmp
WHERE distance < 51
AND speed = spd.speed)
OR spd.distance = (SELECT MIN (distance)
FROM chtmp
WHERE distance > 51
AND speed = spd.speed)
);
It uses the first sub-query to get the records with the right speed,
then the where clause picks out the desired distances for each speed.
cheers
Chris
.
- References:
- sql select question
- From: hilz
- Re: sql select question
- From: ChrisH
- Re: sql select question
- From: hilz
- sql select question
- Prev by Date: How to get all tables without schema?
- Next by Date: How to set number of collumns and rows in JTable after JTable object was created?
- Previous by thread: Re: sql select question
- Next by thread: SQL CREATE TABLE ERROR
- Index(es):