Answer the question
In order to leave comments, you need to log in
Oracle. How to return correct record based on field values?
There is a select that pulls out a record based on the maximum value of the 1st full
SELECT *
FROM
(
SELECT discount, osp_id, sero_id, estpt_id,
ROW_NUMBER() OVER
(PARTITION BY osp_id, sero_id, estpt_id ORDER BY festpae_id DESC) as festpae_id
FROM database1 data1
JOIN database2 data2 ON data2.id = data1.attr_id
WHERE data1.interest_rate = 1
AND data1.ordet_id = data2.id
AND data1.objt_attr_id = data2.objt_attr_id
)
WHERE festpae_id = 1
DISCOUNT OSP_ID SERO_ID ESTPT_ID FESTPAE_ID VALUE
---------- ---------- ---------- ---------- ---------- ----------
50 619356 3931831 2144 NULL 0
40 619356 3931831 2144 NULL 1
30 619356 3931831 2144 2000743 0
15 619356 3931831 2144 2000744 1
DISCOUNT OSP_ID SERO_ID ESTPT_ID FESTPAE_ID VALUE
---------- ---------- ---------- ---------- ---------- ----------
50 619356 3931831 2144 NULL 0
Answer the question
In order to leave comments, you need to log in
You do not try to solve this problem head-on. Look, your bottleneck is related to the last condition. Divide it into two conditions, the first one takes the maximum of the values, or if the value is null, then search by the second condition.
It is important to understand here that they would not work for you at the same time. Another option is to wrap this request, if you have it in a function, of course.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question