【发布时间】:2021-04-05 09:12:28
【问题描述】:
我有一个 SQLite 表,其中包含以下字段,这些字段表示从存储在磁盘上的单个文件中提取的元数据。每个文件都有一个记录:
__path denotes the full path and filename (in effect the PK)
__dirpath denotes the directory path excluding the filename
__dirname denotes the directory name in which the file is found
refid denotes an attribute of interest, pulled from the underlying file on disk
- 文件在创建时按 __dirname 分组和存储
- 中的所有文件 __dirname 应该具有相同的 refid,但 refid 有时不存在
- 作为起点,我想确定每个 __dirpath 有不合格的文件。
我对识别违规文件夹的查询如下:
SELECT __dirpath
FROM (
SELECT DISTINCT __dirpath,
__dirname,
refid
FROM source
)
GROUP BY __dirpath
HAVING count( * ) > 1
ORDER BY __dirpath, __dirname;
是否可以遍历查询的结果并将每个结果用作另一个查询的输入,而无需使用 Python 和 SQLite 之类的东西?例如,查看属于失败集的记录:
SELECT __dirpath, refid
FROM source
WHERE __dirpath = <nth result from aforementioned query>;
【问题讨论】:
标签: sql sqlite loops count subquery