SELECT p.proj_id,
       p.proj_name,
       rt.rtag_name,
       rm.rtag_id,
       rm.total_packages,
       rm.autobuilt,
       rm.lines_of_code,
       rm.unit_tested,
       rm.autotested,
       CASE
         WHEN rm.branches = 0 THEN NULL ELSE rm.branches
       END AS branches,
       rm.last_build_time
  FROM projects p,
       release_metrics rm,
       release_tags rt
 WHERE p.proj_id = rt.proj_id
   AND rm.rtag_id = rt.rtag_id
   AND p.proj_id = :PROJ_ID
 ORDER BY
       CASE
         WHEN rm.last_build_time IS NULL THEN 2 ELSE 1
       END,
       UPPER(rt.rtag_name),
       rm.last_build_time DESC,
       rm.rtag_id DESC