如何解决递归查询计算文件夹大小
我尝试在 sql Server 中执行以下场景:
Root Folder (dataID - 001)
Folder A (dataid-123)
child folder 1
doc1 (size-6 mbs)
doc2 (size- 10 mbs)
child folder 2
doc3 (size - 1 mbs)
doc4 (size- 50 mbs)
Folder B (dataId- 456)
child folder 1
doc1 (size-4 mbs)
doc2 (size- 8 mbs)
child folder 2
doc3 (size - 8 mbs)
doc4 (size- 3 mbs)
child folder 3
doc5 (size - 3 mbs)
doc6 (size- 7 mbs)
SubChild folder 1 for child folder 3
doc 7 (size - 9 mbs)
SubSubChild Folder1 for SubChild folder1
doc 8 (size 5 mbs)
我试图获得的输出格式如下:
Name Count of Docs Total Folder Size:
FolderA 4 67Mbs
FolderB 8 47Mbs
如果我提供根文件夹 ID,我所形成的查询只允许我获取所有文档的大小和数量:
WITH n(DataID,Name,ParentID,SubType,versionnum) AS
(SELECT DataID,versionnum
FROM DTreeCore
WHERE DataID = 001
UNION ALL
SELECT nplus1.DataID,nplus1.Name,nplus1.ParentID,nplus1.SubType,nplus1.versionnum
FROM DTreeCore as nplus1,n
WHERE n.DataID = nplus1.ParentID)
SELECT COUNT(d3.docid) AS "Number of Docs",SUM(d3.datasize) /(1024 *1024) "Megabytes"
FROM
n,dversdata d3
WHERE
n.dataid = d3.docid AND
n.versionnum = d3.version
请告诉我如何实现所需的输出。谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。