user_id date fieldid fieldvalue fromvalue Tovalue action
1 2020-01-01 1 a NULL 0 C
2 2020-01-01 1 a NULL 0 C
2 2020-01-01 1 a NULL 0 N
2 2020-01-02 1 a NULL 0 C
Currently cte query has returns this value. I am trying to delete the the entry both action = c and action = N for an user given date, fieldid, fieldvalue. In this case 1st row and last row must be returned. Row 2nd and 3rd must be deleted since one of the row as N in it.
I am not sure how to add a condition to delete in this case either in self-join or within cte. Any help is much appreciated.