3

我正在尝试获取重复项的详细列表,Foldername即重复值。我需要重复实例和其他相应列的计数,例如FullPath每个重复实例。

我正在尝试返回每个完整路径的列表及其对应的文件夹名称计数,以及其他列,例如单位、大小等。

FolderName (has the possibility of a duplicate)
FullPath (is completly unique)

我对此进行了一些尝试;在 SQL Server 中,这似乎更明显......但在 Access 中,我有点迷失了。

这是我到目前为止提出的基本 SQL:

    /* ''''''''''''''Works but doesn't return Count'''''''''''''' */
Select Snapshot.Unit, Snapshot.FolderName, Snapshot.FullPath
From Snapshot
Where Snapshot.FolderName in 
(
    Select Snapshot.FolderName
    From Snapshot
    Group by Snapshot.Foldername
    Having Count(Snapshot.FolderName)> 1
)
Order by Snapshot.FolderName, Snapshot.FullPath

这是我想获得的示例输出:

Unit       FolderName     FullPath                          Count
BCU        Misc           C:\blah\blah\blah\Misc            2
ENV        Misc           R:\blah\blah\blah\Misc            2
CLR        Monkey         Q:\blah\blah\blah\blah\Monkey     17
ATL        Zebra          Z:\blah\blah\zoo\Zebra            24

我参考过: 在 Access SQL 查询中使用 count() 时遇到问题

4

1 回答 1

5

在子查询中进行计数并INNER JOIN快照到子查询。

SELECT s.Unit, s.FolderName, s.FullPath, sub.num_dupes
FROM
    Snapshot AS s
    INNER JOIN
    (
        SELECT FolderName, Count(*) AS num_dupes
        FROM Snapshot
        GROUP BY FolderName
        HAVING Count(*)> 1
    ) AS sub
    ON s.FolderName = sub.FolderName
ORDER BY s.FolderName, s.FullPath
于 2012-10-26T18:57:34.073 回答