Skip to content

Instantly share code, notes, and snippets.

@jgreco
Last active August 26, 2019 06:41
Show Gist options
  • Save jgreco/09d1d4899178b2db484a667524936ad0 to your computer and use it in GitHub Desktop.
Save jgreco/09d1d4899178b2db484a667524936ad0 to your computer and use it in GitHub Desktop.
(query-exec (sqldb-param)
(prepared (string* "INSERT OR REPLACE INTO TagCardinalities (a,b,cardinality)"
" SELECT min($1,t.tag_id),max($1,t.tag_id),ifnull(sub.cnt,0) "
" FROM Tags t LEFT JOIN"
"(SELECT tag_id, COUNT(*) as cnt FROM FileTags WHERE file_id IN "
"(SELECT file_id FROM FileTags WHERE tag_id=$1)"
"GROUP BY tag_id) AS sub"
"ON t.tag_id = sub.tag_id"))
a-id)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment