/* Formatted on 2006/08/25 11:04 (Formatter Plus v4.8.6) */
SELECT wip.pv_id, pv.pkg_version, pkg.pkg_name, 'WIP' AS state
  FROM work_in_progress wip, package_versions pv, PACKAGES pkg
 WHERE wip.rtag_id = :rtag_id AND pv.pv_id = wip.pv_id
       AND pv.pkg_id = pkg.pkg_id
UNION
SELECT pl.pv_id, pv.pkg_version, pkg.pkg_name, 'PENDING' AS state
  FROM planned pl, package_versions pv, PACKAGES pkg
 WHERE pl.rtag_id = :rtag_id AND pl.pv_id = pv.pv_id
       AND pkg.pkg_id = pv.pkg_id
ORDER BY STATE desc, pkg_name, pkg_version asc
