2017-09-07 195 views

回答

1

使用TOPORDER BY

select top 1 * 
from t 
order by date desc; 

編輯:

如果你想每一個碼的最後日期,然後使用相關子查詢:

select t.* 
from t 
where t.date = (select max(t2.date) from t t2 where t2.code = t.code); 
+0

謝謝,但是這隻會返回來自整個數據庫的最後日期的事務。 我需要每個代碼的最後日期。 –

0

select * from tblName where DocumentDate in (select max(DocumentDate) from tblName)

請使用這個

0

您可以創建連接查詢。例如發現MAX(DocumentDate)

SELECT DocumentNumber, Code, SoldPuncte, DocumentDate 
from yourTable a inner join 
      (SELECT DocumentNumber, Code, SoldPuncte, MAX(DocumentDate) as 
      DocumentDate 
      from yourTable group by DocumentNumber) b 
on a.DocumentNumber=b.DocumentNumber and a.DocumentDate = b.DocumentDate 
0

如果你需要每個碼最後日期,那麼試試這個

SELECT Code, MAX(DocumentDate) 
FROM table 
GROUP BY Code 
相關問題