2017-09-07 188 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 
相关问题