This is a very good opportunity for analytic functions. Try this:
select t.*
from (select t.*,
lag(rep_cat) over (partition by name order by year) as prev_rep_cat
from t
) t
where rep_cat <> pre_rep_cat
Note: This also tells you what the previous value is i the prev_rep_cat
field. Also, because NULL
automatically fails the comparison, you will not get the first row for each name. (If you wanted that, then include or prev_rep_cat is null
in the where
clause.)