gpt4 book ai didi

sql - Access SQL - 在计数查询中显示附加列

转载 作者:行者123 更新时间:2023-12-01 02:31:36 25 4
gpt4 key购买 nike

我正在尝试获取重复项的详细列表,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

我引用了: Having trouble using count() in Access SQL query

最佳答案

在您的子查询中进行计数,并将 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

关于sql - Access SQL - 在计数查询中显示附加列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13092613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com