I'm trying to write a query that will remove a "duplicate" value if it's before a change in the value. For example, I have the following data:
id, date_recived, name1, percent
1, 8/19/13, Joe, 2
2, 8/15/13, Joe, 3
3, 8/12/13, Joe, 2
4, 4/08/13, Joe, 2
In this example I need to remove only the row with id 3 because there was no change in the percent. I've tried using Row_Number, however when I partition by the name and percent the data appears as follows:
id, date_recived, name1, percent, Row_Number
1, 8/19/13, Joe, 2, 3
2, 8/15/13, Joe, 3, 1
3, 8/12/13, Joe, 2, 2
4, 4/08/13, Joe, 2, 1
This won't work because 1 would be thrown out and I need to keep it. Any help would be appreciated.
Thanks,
EDIT:
The query is (from the comment):
WITH feedback_On_Same_Date AS (
SELECT id, received_dt, participant_nm, pretax_deferral_prcnt,
ROW_NUMBER() OVER(PARTITION BY participant_nm, received_dt ORDER BY received_dt DESC, id DESC) AS RowNumberByDt
FROM be_ing_feedback
)
SELECT *, ROW_NUMBER() OVER(PARTITION BY participant_nm, pretax_deferral_prcnt ORDER BY received_dt ASC, id ASC) AS RowNumberByDef
FROM feedback_On_Same_Date
WHERE RowNumberByDt = 1
ORDER BY participant_nm ASC, received_dt DESC