# Count children of FINDER_ROOTs without using PR_SUBFOLDERS
#
SELECT COUNT(*)
FROM properties AS p
INNER JOIN hierarchy AS hp ON p.hierarchyid=hp.id AND p.tag=12289
INNER JOIN hierarchy AS hc ON hp.id=hc.parent
WHERE p.val_string="FINDER_ROOT";

# Uses PR_SUBFOLDERS hack to count
# (It's an integer rather than a boolean in the KC DB)
#
SELECT SUM(p2.val_ulong)
FROM properties AS p1
INNER JOIN properties AS p2
ON p1.hierarchyid=p2.hierarchyid AND p1.tag=12289 AND p2.tag=13834
WHERE p1.val_string="FINDER_ROOT";

# Show distribution
#
SELECT p2.val_ulong
FROM properties AS p1
INNER JOIN properties AS p2
ON p1.hierarchyid=p2.hierarchyid AND p1.tag=12289 AND p2.tag=13834
WHERE p1.val_string="FINDER_ROOT"
ORDER BY p2.val_ulong DESC
LIMIT 25;
