SELECT pkg.pkg_name,
       pv.pkg_version,
       pv.is_autobuildable,
       pm.*,
       (CASE
         WHEN ut.test_types_fk IS NOT NULL AND ut.test_types_fk != 1 THEN 'Y' ELSE 'N'
        END) AS unit_tested,
       (CASE
         WHEN ut.test_types_fk = 7 THEN 'Y' ELSE 'N'
        END) AS autotested
  FROM package_metrics pm,
       package_versions pv,
       packages pkg,
       unit_tests ut
 WHERE pv.pkg_id = pkg.pkg_id
   AND pv.pv_id = :PV_ID
   AND pm.pv_id = pv.pv_id
   AND ut.pv_id (+) = pv.pv_id
