Skip to content

Instantly share code, notes, and snippets.

@devyn
Created February 9, 2014 12:13
Show Gist options
  • Save devyn/404797e2c6c5fbbd01c3 to your computer and use it in GitHub Desktop.
Save devyn/404797e2c6c5fbbd01c3 to your computer and use it in GitHub Desktop.
SELECT
r1.destination AS file_id,
count(r2.id) AS subrelations,
octet_length(f.contents) AS bytes,
r1.name AS name
FROM
relations AS r1
INNER JOIN
files AS f ON f.id = r1.destination
LEFT OUTER JOIN
relations AS r2 ON r2.source = r1.destination
WHERE
r1.source = ?
GROUP BY
r1.name,
r1.destination,
f.contents
ORDER BY
r1.name ASC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment