具有不同ID

时间:2016-03-22 19:34:38

标签: sql vba ms-access access-vba duplicates

我有一个查询涉及7个表(但我认为主要问题是[tbl_Records]

表格设置:

qry_CofC :[ID],[描述],[制造商],[型号],[S_N],[容差],[位置],[校准频率]

tbl_Instruments :[备注]

tbl_Records :[Cal_Date],[路径]

tbl_Unit :[单位]

tbl_Status :[txt_Status]

tbl_Category :[类别]

tbl_Used_By :[姓名]

下面的

是没有[tbl_Records.Path]的查询的快照 [enter image description here

但是当我添加[tbl_Records.Path]时,会出现重复的记录 enter image description here 这是我的sql:

SELECT
    qry_CofC.ID, [tbl_Instruments].[Type] & "-" & [tbl_Instruments].[Item] AS Tool_ID,
    tbl_Unit.Unit, tbl_Status.txt_Status AS Status,
    tbl_Category.Category, tbl_Used_By.Name AS Used_By,
    Max(tbl_Records.Cal_Date) AS MaxOfCal_Date,
    Max(DateAdd("d",[qry_CofC]![Lead],(DateAdd("m",[qry_CofC]![Calibration Freq],[tbl_Records]![Cal_date])))) AS Due_Date,
    Max(DateDiff("d",Date(),DateAdd("d",[qry_CofC]![Lead],DateAdd("m",[qry_CofC]![Calibration Freq],[tbl_Records]![Cal_date])))) AS Due,
    tbl_Instruments.Remark,
    tbl_Records.Path
FROM tbl_Unit
    INNER JOIN (tbl_Status
        INNER JOIN (tbl_Used_By
            INNER JOIN (tbl_Category
                INNER JOIN (tbl_Tol
                    INNER JOIN ((qry_CofC INNER JOIN tbl_Instruments ON qry_CofC.[ID] = tbl_Instruments.[ID])
                    INNER JOIN tbl_Records ON tbl_Instruments.[ID] = tbl_Records.[Inst_ID])
                    ON tbl_Tol.ID = tbl_Instruments.Accuracy)
                ON tbl_Category.ID = tbl_Instruments.Category)
            ON tbl_Used_By.ID = tbl_Instruments.Used_By_Operator)
        ON tbl_Status.Index = tbl_Instruments.Status)
    ON tbl_Unit.ID = tbl_Instruments.Unit

GROUP BY qry_CofC.ID, [tbl_Instruments].[Type] & "-" & [tbl_Instruments].[Item], tbl_Unit.Unit, tbl_Status.txt_Status, tbl_Category.Category, tbl_Used_By.Name, tbl_Instruments.Remark, tbl_Records.Path

ORDER BY [tbl_Instruments].[Type] & "-" & [tbl_Instruments].[Item];

非常感谢您的帮助!

0 个答案:

没有答案