尝试使用MIN()获取最早的日期

时间:2016-02-17 19:50:29

标签: sql ms-access ms-access-2013 min

SELECT ID, AppID, Description, Min([Transaction Date]) AS 'Transacton Date'
FROM AppProsHist
WHERE [Description]='Non-Final Rejection'
GROUP BY ID, AppID, Description

我认为这只允许在我的表格中显示第一个(最早的)交易日期,但是,这仍然显示每个交易日期。有没有办法改变这一点,以便我只收到一个ID,AppID,描述的日期?

1 个答案:

答案 0 :(得分:2)

您应该使用ORDER BYLIMIT 1来获取有序集的第一条记录。订购时ASCDESC将设置排序方向。所以试试

SELECT TOP 1 ID, AppID, Description, Min([Transaction Date]) AS TransactionDate
FROM AppProsHist
WHERE [Description]='Non-Final Rejection'
GROUP BY ID, AppID, Description
ORDER BY TransactionDate DESC, ID