디스크에 저장된 개별 파일에서 가져온 메타 데이터를 나타내는 다음 필드가있는 단일 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
문제가되는 폴더를 식별하기위한 내 쿼리는 다음과 같습니다.
SELECT __dirpath
FROM (
SELECT DISTINCT __dirpath,
__dirname,
refid
FROM source
)
GROUP BY __dirpath
HAVING count( * ) > 1
ORDER BY __dirpath, __dirname;
SQLite와 함께 Python과 같은 것을 사용하지 않고 쿼리 결과를 반복하고 각 결과를 다른 쿼리의 입력으로 사용할 수 있습니까? 예를 들어, 실패한 세트에 속하는 레코드를 보려면 다음을 수행하십시오.
SELECT __dirpath, refid
FROM source
WHERE __dirpath = <nth result from aforementioned query>;
문제가되는 모든 행을 원하는 경우 한 가지 옵션은 다음과 같습니다.
select t.*
from (
select t.*,
min(refid) over(partition by __dirpath, __dirname) as min_refid,
max(refid) over(partition by __dirpath, __dirname) as max_refid
from mytable t
) t
where min_refid <> max_refid
논리는 refid
동일한 dir 경로와 dir 이름을 가진 각 행 그룹에 대해 최소값과 최대 값을 비교하는 것 입니다. 그들이 다르면 행이 불쾌합니다.
우리는 또한 exists
-가능한 null
값을 더 잘 처리 할 수 있습니다 refid
.
select t.*
from mytable t
where exists (
select 1
from mytable t1
where
t1.__dirpath = t.__dirpath
and t1.__dirname = t.__dirname
and t1.ref_id is not t.ref_id
)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다