Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Help Need to build this logic
Greetings,
Table Structure:
Table1
symbol orders ttime
Requirement: Want to arrange all records, symbolwise, based on orders
(asc order).
Among that, if a particular symbol have records in the range TTIME
BETWEEN 9300 AND 1530, then
I want to extract MIN(TTIME) within that range else MIN(TTIME) of
whatever available records.
I want to achieve this using a single query.
Example:
Table1
symbol orders ttime A 2 9300 A 2 9450 A 2 1030 A 2 9451 A 2 1530 A 2 1600 A 2 1700 B 3 9300 B 4 1600 C 3 1600
I want to get all records with maximum orders (in desc order) for each symbol.
Output:
Symbol Orders ttime
A 2 9300 A 2 9450 A 2 9451 A 2 1030 A 2 1530 A 2 1600 A 1 9300 A 2 1700 B 4 9300 B 4 1600 C 3 1600
Out of this subset I want to get all records with ttime falling between
9450 to 1530 to appear first in asc. if there is no record within this
range
then I want to go for normal asc order on ttime.
Ouput:
Symbol Orders ttime A 2 9450 A 2 1030 A 2 1530 A 2 1600 A 2 9300 B 4 9450 B 4 1030 B 4 1600 C 3 1600
Finally I want to extract only first record
Final output:
A 2 9450 B 4 9300 C 3 1600
Any help would be appreciated.
TIA Received on Tue Jan 16 2007 - 06:35:52 CST
![]() |
![]() |