How can i get the result of the first query as a parameter for the second query.
the goal is to get the smaller date and apply it to the second query.
SELECT
MAX(datе)
FROM
datе_table
WHERE
datе <= TO_DATE('2022-07-31', 'YYYY-MM-DD')
select name
from table_name
where datе = MAX(datе)
第一個查詢的結果必須應用在第二個查詢的 where 子句中
uj5u.com熱心網友回復:
不只是 max(date),而是使用整個第一個查詢:
select name
from table_name
where date = (select max(date)
from date_table
where date <= date '2022-07-31'
)
(當然,列名不能只是date; 那是為資料型別名稱保留的)
如果您計劃在 PL/SQL 代碼中重用最大日期,則將其存盤到(本地)變數中,例如
declare
l_max_date date;
l_fun1_retval number;
l_fun2_retval varchar2(20);
l_val number;
begin
select max(date) into l_max_date
from date_table
where date <= date '2022-07-31';
l_fun1_retval := function1 (l_max_date);
l_fun2_retval := function2 (l_max_date);
select count(*) into l_val
from table_3
where date_value = l_max_date;
end;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/522702.html
標籤:甲骨文oracle19c
上一篇:制作總和列并在欄位旁邊顯示結果
