我有這樣一個查詢結果
我想只有那些有col2 < 01/04/2001的stud或者那些有col2 < 01/04/2001和col2 >= 01/04/2001的stud,但是沒有那些只有col2 > 01/04/2001的stud。 所以我想只保留這些行
任何想法,請? 預先謝謝你
uj5u.com熱心網友回復:
我建議exists:
select t.*
from t.
where exists (select 1)
from t t2
where t2.col1 = t.col1 and
t2.col2 < date '2001-04-01'
你也可以用視窗函式來表述:
select t.*
from (select t.*,
min(col2) over (partition by col1) as min_col2
from t
) t
where min_col2 < date '2001-04-01';
uj5u.com熱心網友回復:
為了滿足你的條件,你可以遵循下面這個規則。 首先(在子查詢中),選擇所有col2值小于01/04/2001的記錄,然后選擇所有與子查詢中過濾的記錄具有相同col1值的記錄。
select t1.*
from YourTable t1.
where t1.col1 in (
select t2.col1 from YourTable t2
where t2.col2 < to_date('01/04/2001', 'DD/MM/YYYY')
)
order by col3
;
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/308134.html
標籤:
