Question: Hi everyone i have like this value in my column:

```
<?xml version="1.0" encoding="UTF-8"?><?dsk-revision 1.0?><Descriptor><pde><a><dov>784512</dov></a></pde></Descriptor>

```

I would retrieve just :

```
<dov>784512</dov>

```

Do you have any ideas?

**Thank you !**

Answer: 
This is a gaps-and-islands problem. I think `lag()` is the simplest approach:

```
select user_id, plan_type, created
from (select t.*,
             lag(plan_type) over (partition by user_id order by created) as prev_plan_type
      from t
     ) t
where prev_plan_type is null or prev_plan_type <> plan_type;

```

This assumes that plan types can move back to another value and you want each one. 

If not, just use aggregation:

```
select user_id, plan_type, min(created)
from t
group by user_id, plan_type;

```
use `lag()`

```
select * from
(
select user_id, plant_type, lag(plan_type) over (partition by user_id order by created) as changes, created
from tablename
)A where plan_type<>changes and changes is not null

```