Skip to content

Instantly share code, notes, and snippets.

@gordonje
Created September 13, 2016 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gordonje/06f17a15f5b6771c2de2c24990f621db to your computer and use it in GitHub Desktop.
Save gordonje/06f17a15f5b6771c2de2c24990f621db to your computer and use it in GitHub Desktop.
joining f460s to filer_links
-- 1,471 uncaptured records
SELECT COUNT(DISTINCT cvr."FILER_ID")
FROM "CVR_CAMPAIGN_DISCLOSURE_CD" cvr
JOIN f460_summary f460
ON cvr."FILING_ID" = f460.filing_id
AND cvr."AMEND_ID" = f460.amend_id
JOIN "FILER_XREF_CD" x
ON x."XREF_ID" = cvr."FILER_ID"
LEFT JOIN (
SELECT "FILER_ID_A"::varchar as filer_id
FROM "FILER_LINKS_CD"
UNION
SELECT "FILER_ID_B"::varchar as filer_id
FROM "FILER_LINKS_CD"
) links
ON links.filer_id = cvr."FILER_ID"
WHERE links.filer_id IS NULL;
-- 7 uncaptured records
SELECT COUNT(DISTINCT cvr."FILER_ID")
FROM "CVR_CAMPAIGN_DISCLOSURE_CD" cvr
JOIN f460_summary f460
ON cvr."FILING_ID" = f460.filing_id
AND cvr."AMEND_ID" = f460.amend_id
JOIN "FILER_XREF_CD" x
ON x."XREF_ID" = cvr."FILER_ID"
LEFT JOIN (
SELECT "FILER_ID_A" as filer_id
FROM "FILER_LINKS_CD"
UNION
SELECT "FILER_ID_B" as filer_id
FROM "FILER_LINKS_CD"
) links
ON links.filer_id = x."FILER_ID"
WHERE links.filer_id IS NULL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment