可以使用row_number()這樣的(我'加入材料B,如果你需要找到在組中的所有材料量「a」和「 b「):
WITH a(Material, Description , Quantity , sDate) AS
(SELECT 'b', 133, 1200 , to_date('26-09-2016 12:33','dd-mm-yyyy hh24:mi') FROM dual UNION ALL
SELECT 'b', 133, 2200 , to_date('29-09-2016 12:33','dd-mm-yyyy hh24:mi') FROM dual UNION ALL
SELECT 'a', 133, 200 , to_date('26-09-2016 12:33','dd-mm-yyyy hh24:mi') FROM dual UNION ALL
SELECT 'a', 133, 400 , to_date('27-09-2016 10:33','dd-mm-yyyy hh24:mi') FROM dual )
SELECT *
FROM (SELECT a.*,
row_number() over(partition BY material order by sdate DESC) rn
FROM a)
WHERE rn = 1
MATERIAL DESCRIPTION QUANTITY SDATE RN
-------- ----------- ---------- --------- ----------
a 133 400 27-SEP-16 1
b 133 2200 29-SEP-16 1
在你的where子句中使用max date .. – XING
什麼版本的Oracle? (總是聲明,如果你不知道,通過運行'select * from v $ version'找到。)在Oracle 12中,你可以使用'fetch first | last'並避免子查詢。 – mathguy