我有以下数据
CompId PersonelNo EduId RecordsDay DateEs
 1      1000        1       2       1370
 1      1000        2       10      1370
 1      1002        2       5       1380
 1      1003        1       4       1391
 1      1003        2       7       1391
我想为最大 EduID 的 RecordsDay 添加 (1392-1390=2) 和 DateE 小于或等于 1390 的记录,并为 RecordsDay 添加 (DateEs -1390) 最大 EduID 和 DateE 大于 1390 的记录
所以数据会是这样的
 CompId PersonelNo EduId RecordsDay DateEs
  1      1000        1       2       1370 // record is the same becuase eduID is not Max for this Personel
  1      1000        2       12      1370 // this is max EduId for this personel and DateEs is less than 1390 so (1392-1390) +10 = 12
  1      1002        2       7       1380 //this is the only record for this personel and DateEs is less than 1390(1392-1390) +5 = 7
  1      1003        1       4       1391 // record is the same becuase eduID is not Max for this Personel
  1      1003        2       8       1391 // this is max EduId for this personel and DateEs is Greater than 1390 so (1391-1390) +7 = 8
我想有 TSQl。我正在努力,但可以写到现在