仅显示数据库中的数据超过5次

时间:2016-08-03 21:17:16

标签: sql ms-access ms-access-2010

我有一份报告,除了我的最后一道障碍之外还能正常工作。

表格示例,第A行:

John
John
Mike
John
Steve
Steve

我只希望我的报告显示在我的表格中的名称5次或更多。我正在努力找出我需要设置的标准

有什么建议吗?

来自评论:

SELECT tblSourceData.Athlete, Max(tblSourceData.Swim) AS MaxOfSwim, 
    Max(tblSourceData.Bike) AS MaxOfBike, Max(tblSourceData.Run) AS MaxOfRun 
FROM tblSourceData 
GROUP BY tblSourceData.Athlete, tblSourceData.Gender 
HAVING (((tblSourceData.Athlete)>="5") AND ((tblSourceData.Gender)="f")); 

1 个答案:

答案 0 :(得分:2)

您需要HAVING clause

SELECT aName, Count(aName) AS NumName
FROM myTable
GROUP BY aName
HAVING Count(aName)>=5

修改

你可能想要

SELECT tblSourceData.Athlete, Max(tblSourceData.Swim) AS MaxOfSwim, 
    Max(tblSourceData.Bike) AS MaxOfBike, Max(tblSourceData.Run) AS MaxOfRun 
FROM tblSourceData 
WHERE tblSourceData.Gender="f"
GROUP BY tblSourceData.Athlete 
HAVING Count(tblSourceData.Athlete)>=5

不使用聚合列的标准将进入WHERE子句。