sql server 2008 - Update specific records based on some group -


I am using SQL Server 2008 R2 I

Near Database Table contains some user data:

  id UserId Sys Dia ReadType DataId IsDeleted 1 10 98 65 Final 1390556024216 0 2 10 99 69 Average 1390556024216 0 3 10 102 96 Final 1390562788540 0 4 10 102 96 Average 1390562788540 0 5 11 130 98 Final 1390631241547 0 6 11 130 98 Average 1390631241547 0 7 2 285 199 First 1390770562374 0 8 2 250 180 Last 1390770562374 9 2 267 189 Average 1390770562374 0 10 1 258 180 First 13 9 1191009457 0 11 1 258 180 Final 1391191009457 0 12 1 258 180 Avg 1391191009457 13 137 285 199 Extras 1391191009457 0 14 22 110 78 Final 1391549 208338 15 15 22 123 83 Previous 1391549208349 0   

In this table, there are records that are similar to same data ID , but separate readings type .

I want to set IsDeleted = 1 for the record containing ReadingType = 'last' and ReadingType = 'average' With the same data id, sis, die and user id .

Then the desired result may be shaken:

  ID UserId read the Sys Dia DataId IsDeleted 1 10 98 65 Final 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 Final 1390631241547 1 6 11 130 98 Average 1390631241547 0 7 2 285 199 First 1390770562374 0 8 2 250 180 Last 1390770562374 9 2 267 189 Average 1390770562374 0 10 1 258 180 First 13 9 1191009457 0 11 1 258 180 Final 1391191009457 1 12 1 258 180 Average 1391191009457 0 13 1 285 199 Extra 1391191009457 0 14 22 110 78 Final 13 91549208338 15 15 123 123 Final 1391549208349 0   

Here Record marked with id 3, 5 and 11 as deleted As they can help someone else with any other record, such as the same userid, sis, die, data id and reading type = "last", how to find and update any such record

"itemprop =" text ">

Just update with the current update:

  update t Set isDeleted = 1 where reading type = 'last' and current (select from * T as T1 WHERE T1 reading type = 'average' and T1. Etaid = Tikdetaid and T1. SYS = T. SS and T1 Dia = TDIA and T1. User id = t user id)   



Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -