简体   繁体   English

SQL ACCESS - 选择max(日期)和相应的值

[英]SQL ACCESS - select max(date) and corresponding value

How can I get the corresponding value of MAX(date). 如何获得MAX(日期)的相应值。 Access it returns me an error when I select directly the column with the specified value. 当我直接选择具有指定值的列时,访问它会返回错误。

For example, I want to be shown only the line from the image. 例如,我想只显示图像中的线条。

Thank you. 谢谢。

在此输入图像描述

Use TOP and ORDER BY : 使用TOPORDER BY

select top 1 *
from t
order by date desc;

EDIT: 编辑:

If you want the last date per code, then use a correlated subquery: 如果您想要每个代码的最后日期,请使用相关子查询:

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)

请用这个

You mast creat the join query. 你创建了连接查询。 For example find MAX(DocumentDate) : 例如,找到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

If you need last date per code then try this one 如果您需要每个代码的最后日期,请尝试这个

SELECT Code, MAX(DocumentDate)
FROM table
GROUP BY Code

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM