Template and number of linked projects

Contribute from: Tim Hartman (TX3)

Note: NULLS are converted to zeros

 

DB TYPE:           ORACLE 11g

Query:

SELECT
a.domain_name "Domain",
a.project_name "Project",
CASE WHEN b.numlinks is null THEN 0 ELSE b.numlinks END "Linked"
FROM
projects a
left join (select prl_from_project_uid, count(*) as numlinks from project_links group by prl_from_project_UID) b on a.project_uid = b.prl_from_project_uid
WHERE
is_template='Y'
ORDER BY domain_name, project_name