Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何在ms access中使用DISTINCT?_Sql_Ms Access_Ms Access 2007_Ms Access 2010_Ms Access 2013 - Fatal编程技术网

Sql 如何在ms access中使用DISTINCT?

Sql 如何在ms access中使用DISTINCT?,sql,ms-access,ms-access-2007,ms-access-2010,ms-access-2013,Sql,Ms Access,Ms Access 2007,Ms Access 2010,Ms Access 2013,我有以下疑问: SELECT DISTINCT AwardDescriptions.aID, CostCentres.cCC FROM AwardDescriptions INNER JOIN CostCentres ON AwardDescriptions.aID = CostCentres.cNumber ORDER BY CostCentres.cCC; 出于某种原因,当我运行查询时,它仍然显示所有重复的值。 有什么建议吗?您可以使用分组方式获得最小值或最大值: SELECT M

我有以下疑问:

SELECT DISTINCT AwardDescriptions.aID, CostCentres.cCC 
FROM  AwardDescriptions 
INNER JOIN CostCentres ON AwardDescriptions.aID = CostCentres.cNumber 
ORDER BY CostCentres.cCC;
出于某种原因,当我运行查询时,它仍然显示所有重复的值。
有什么建议吗?

您可以使用
分组方式
获得最小值或最大值:

SELECT MAX(AwardDescriptions.aID) as aID, CostCentres.cCC 
FROM  AwardDescriptions INNER JOIN
      CostCentres
      ON AwardDescriptions.aID = CostCentres.cNumber 
GROUP BY CostCentres.cCC
ORDER BY CostCentres.cCC;

你看到使用相同的aID和cCC的重复行了吗?@AlexK。我知道我现在可能出了什么问题。。。好的,问题重新表述:我如何修改我的查询以便没有重复的成本中心?好的,如果一个特定的援助有两个不同的cCC值,您想要哪一个?您可以选择一个聚合(例如,
min()/max()
)并使用
groupby
@carrots。您能提供一些示例数据和您想要得到的结果吗?@AlexK。一个辅助设备可以有两个不同的cCC,同样,一个cCC可以有两个不同的辅助设备。我真的不在乎援助,我只是想让它呈现cCC的所有不同的价值。谢谢,这是有效的!我很难理解为什么使用MAX和GROUP BY可以实现这一点。我以为MAX会从aID中获得一个最高的值,但它如何呈现所有的aID呢?@carrots。我不明白你的问题。此查询为每个
CostCenter.cCC
显示一个
aID
值,这似乎就是您的问题所在。