I am using `SQL Server 2008 R2`. 

I am having a database table that contains some user data as given below : 

```
Id  UserId  Sys     Dia     ReadingType     DataId              IsDeleted
1   10      98      65      last            1390556024216       0
2   10      99      69      average         1390556024216       0
3   10      102     96      last            1390562788540       0
4   10      102     96      average         1390562788540       0
5   11      130     98      last            1390631241547       0
6   11      130     98      average         1390631241547       0
7   2       285     199     first           1390770562374       0
8   2       250     180     last            1390770562374       0
9   2       267     189     average         1390770562374       0
10  1       258     180     first           1391191009457       0
11  1       258     180     last            1391191009457       0
12  1       258     180     average         1391191009457       0
13  1       285     199     additional      1391191009457       0
14  22      110     78      last            1391549208338       0
15  22      123     83      last            1391549208349       0

```

In this table, there are records that are having the `same DataId` but `different ReadingType`. 

I want to set `IsDeleted=1` for the records having `ReadingType='last'` and having a record with `ReadingType='average'` with the `same DataId, Sys, Dia and UserId`. 

So the Desired result shoul be : 

```
Id  UserId  Sys     Dia     Reading         DataId              IsDeleted
1   10      98      65      last            1390556024216       0
2   10      99      69      average         1390556024216       0
3   10      102     96      last            1390562788540       1
4   10      102     96      average         1390562788540       0
5   11      130     98      last            1390631241547       1
6   11      130     98      average         1390631241547       0
7   2       285     199     first           1390770562374       0
8   2       250     180     last            1390770562374       0
9   2       267     189     average         1390770562374       0
10  1       258     180     first           1391191009457       0
11  1       258     180     last            1391191009457       1
12  1       258     180     average         1391191009457       0
13  1       285     199     additional      1391191009457       0
14  22      110     78      last            1391549208338       0
15  22      123     83      last            1391549208349       0

```

Here the records with `Id 3, 5 and 11` should be `marked as deleted` as they are `having same UserId, Sys, Dia, DataId and ReadingType="last" with another record having ReadingType="average" with same other fields`.

Can anyone help me how to find out such a records and update them?