SELECT DISTINCT pkg.pkg_name,
       pv.pkg_version,
       pv.is_autobuildable,
       pv.pv_id,
       pm.code_lines,
       pm.branches,
       (CASE
         WHEN ut.test_types_fk IS NOT NULL AND ut.test_types_fk != 1 THEN 'Y' ELSE 'N'
        END) AS unit_tested,
       autotest_qry.autotested
  FROM package_metrics pm,
       package_versions pv,
       packages pkg,
       unit_tests ut,
       (SELECT ut.pv_id, 'Y' AS autotested
          FROM unit_tests ut
         WHERE ut.test_types_fk = 7
       ) autotest_qry
 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
   AND autotest_qry.pv_id (+) = pv.pv_id

