[英]SQL ACCESS - select max(date) and corresponding value
如何獲得MAX(日期)的相應值。 當我直接選擇具有指定值的列時,訪問它會返回錯誤。
例如,我想只顯示圖像中的線條。
謝謝。
使用TOP
和ORDER 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);
select * from tblName where DocumentDate in (select max(DocumentDate ) from tblName)
請用這個
你創建了連接查詢。 例如,找到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
如果您需要每個代碼的最后日期,請嘗試這個
SELECT Code, MAX(DocumentDate)
FROM table
GROUP BY Code
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.