vba访问显示最小日期的重复数据

时间:2017-08-17 10:23:24

标签: sql ms-access

有没有办法找到min(创建日期)并从访问查询中删除它?

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以使用MIN()函数选择MIN()日期的记录。

SELECT Item_Number, Order_Number, Order_Line_Number,  MIN(Creation_Date) 
FROM *tblName*
GROUP BY Item_Number, Order_Number, Order_Line_Number

或者您可以在“创建日期”列中使用MAX()函数来排除具有最小日期的记录。

SELECT Item_Number, Order_Number, Order_Line_Number,  MAX(Creation_Date) 
FROM *tblName*
GROUP BY Item_Number, Order_Number, Order_Line_Number

或者如果您最初提到的确想要使用MIN()日期从MS Access表中删除记录,请使用以下查询。

DELETE **tbl_A.*** FROM 
*tblName tbl_A* INNER JOIN *tblName tbl_B* 
WHERE 
tbl_A.Item_Number = tbl_B.Item_Number
AND
tbl_A.Order_Number = tbl_B.Order_Number
AND
tbl_A.Order_Line_Number = tbl_B.Order_Line_Number
AND
tbl_A.Creation_Date = tbl_B.MIN(Creation_Date)