我有一个Access Query,我用它来根据表单生成报告。我在查询中遇到了重复记录的问题。
经过一番调查后,我发现这是因为我有一个包含多个潜在值的查找字段,并且每次在该字段中存在值时查询都会创建记录,尽管每个值都显示所有值(其中是预期的结果。)
知道如何解决这个问题吗?我只是希望它在查询结果中显示每个记录的一个实例。
我已经尝试将查询设置为使用唯一值和唯一记录,而唯一值只会导致它在我运行查询时提示我输入查找字段的数据。
查询的SQL是:
PARAMETERS [Enter Start Date:] DateTime, [Enter End Date:] DateTime;
SELECT DISTINCTROW RA_Generic.ID, RA_Generic.Title, RA_Generic.Description,
RA_Generic.[Person Carrying Out], RA_Generic.Hazard_1,
RA_Generic.Level_Of_Risk_1, RA_Generic.Control_Measures_1,
RA_Generic.Worst_Possible_Outcome_1, RA_Generic.Level_Of_Risk_1_After,
RA_Generic.Hazard_2, RA_Generic.Level_Of_Risk_2,
RA_Generic.Control_Measures_2, RA_Generic.Worst_Possible_Outcome_2,
RA_Generic.Level_Of_Risk_2_After, RA_Generic.Hazard_3,
RA_Generic.Level_Of_Risk_3, RA_Generic.Control_Measures_3,
RA_Generic.Worst_Possible_Outcome_3, RA_Generic.Level_Of_Risk_3_After,
RA_Generic.Hazard_4, RA_Generic.Level_Of_Risk_4,
RA_Generic.Control_Measures_4, RA_Generic.Worst_Possible_Outcome_4,
RA_Generic.Level_Of_Risk_4_After, RA_Generic.Hazard_5,
RA_Generic.Level_Of_Risk_5, RA_Generic.Control_Measures_5,
RA_Generic.Worst_Possible_Outcome_5, RA_Generic.Level_Of_Risk_5_After,
RA_Generic.Hazard_6, RA_Generic.Level_Of_Risk_6,
RA_Generic.Control_Measures_6, RA_Generic.Worst_Possible_Outcome_6,
RA_Generic.Level_Of_Risk_6_After, RA_Generic.Date_Updated,
RA_Generic.Type_Of_RA, RA_Generic.Specific, RA_Generic.[Hazard Types]
FROM RA_Generic
GROUP BY RA_Generic.ID, RA_Generic.Title, RA_Generic.Description,
RA_Generic.[Person Carrying Out], RA_Generic.Hazard_1,
RA_Generic.Level_Of_Risk_1, RA_Generic.Control_Measures_1,
RA_Generic.Worst_Possible_Outcome_1, RA_Generic.Level_Of_Risk_1_After,
RA_Generic.Hazard_2, RA_Generic.Level_Of_Risk_2,
RA_Generic.Control_Measures_2, RA_Generic.Worst_Possible_Outcome_2,
RA_Generic.Level_Of_Risk_2_After, RA_Generic.Hazard_3,
RA_Generic.Level_Of_Risk_3, RA_Generic.Control_Measures_3,
RA_Generic.Worst_Possible_Outcome_3, RA_Generic.Level_Of_Risk_3_After,
RA_Generic.Hazard_4, RA_Generic.Level_Of_Risk_4,
RA_Generic.Control_Measures_4, RA_Generic.Worst_Possible_Outcome_4,
RA_Generic.Level_Of_Risk_4_After, RA_Generic.Hazard_5,
RA_Generic.Level_Of_Risk_5, RA_Generic.Control_Measures_5,
RA_Generic.Worst_Possible_Outcome_5, RA_Generic.Level_Of_Risk_5_After,
RA_Generic.Hazard_6, RA_Generic.Level_Of_Risk_6,
RA_Generic.Control_Measures_6, RA_Generic.Worst_Possible_Outcome_6,
RA_Generic.Level_Of_Risk_6_After, RA_Generic.Date_Updated,
RA_Generic.Type_Of_RA, RA_Generic.Specific
HAVING (((RA_Generic.Date_Updated) Between [Enter Start Date:] And [Enter
End Date:]))
ORDER BY RA_Generic.ID DESC;
导致问题的字段是HazardTypes
答案 0 :(得分:0)
我将删除GROUP BY
子句DISTINCTROW
,并将HAVING
子句移到WHERE
子句,因为您没有进行任何聚合。< / p>
PARAMETERS [Enter Start Date:] DateTime, [Enter End Date:] DateTime;
SELECT RA_Generic.ID, RA_Generic.Title, RA_Generic.Description,
RA_Generic.[Person Carrying Out], RA_Generic.Hazard_1,
RA_Generic.Level_Of_Risk_1, RA_Generic.Control_Measures_1,
RA_Generic.Worst_Possible_Outcome_1, RA_Generic.Level_Of_Risk_1_After,
RA_Generic.Hazard_2, RA_Generic.Level_Of_Risk_2,
RA_Generic.Control_Measures_2, RA_Generic.Worst_Possible_Outcome_2,
RA_Generic.Level_Of_Risk_2_After, RA_Generic.Hazard_3,
RA_Generic.Level_Of_Risk_3, RA_Generic.Control_Measures_3,
RA_Generic.Worst_Possible_Outcome_3, RA_Generic.Level_Of_Risk_3_After,
RA_Generic.Hazard_4, RA_Generic.Level_Of_Risk_4,
RA_Generic.Control_Measures_4, RA_Generic.Worst_Possible_Outcome_4,
RA_Generic.Level_Of_Risk_4_After, RA_Generic.Hazard_5,
RA_Generic.Level_Of_Risk_5, RA_Generic.Control_Measures_5,
RA_Generic.Worst_Possible_Outcome_5, RA_Generic.Level_Of_Risk_5_After,
RA_Generic.Hazard_6, RA_Generic.Level_Of_Risk_6,
RA_Generic.Control_Measures_6, RA_Generic.Worst_Possible_Outcome_6,
RA_Generic.Level_Of_Risk_6_After, RA_Generic.Date_Updated,
RA_Generic.Type_Of_RA, RA_Generic.Specific, RA_Generic.[Hazard Types]
FROM RA_Generic
WHERE (((RA_Generic.Date_Updated) Between [Enter Start Date:] And [Enter
End Date:]))
ORDER BY RA_Generic.ID DESC;