CREATE OR REPLACE VIEW V_LATEST_RT_CODE_FOR_ENRO AS
/** Show rows from enquiry_roles where they represent the latest instance of an rt_code
associated with an an enquiry.
*/
SELECT prty_id
      ,rt_code
      ,start_date
      ,end_date
      ,enqu_id
  FROM (SELECT enro.*
              ,MAX(start_date) over(PARTITION BY rt_code, enqu_id) AS max_date_rt_code
          FROM enquiry_roles enro)
 WHERE start_date = max_date_rt_code;
