将数据表中的行移动到指定的索引(中心偏移)

时间:2019-01-15 13:16:41

标签: c#

在我的后端,

的DataTable具有40个ID,每个ID在数据库中静态添加了400行,但是每个ID都有另一个具有值的行计数。如果行没有值,则为空。

我希望中心值取决于数学运算结果中的X:  (400-CountOfNotNullValues)/ 2 = X 该X将偏移以向下移动所有行并在上方添加空值。  这是正确的偏移量,但在DB层和SELECT上需要8分钟:

enter image description here
enter image description here
enter image description here

select b.ID, b.cislo AS F_SD, ((a.val - b.F_FMDELTHKTARGAIM)*1000) as val    from
(select ID, F_FMDELTHKTARGAIM, cislo from TM_HP_R_QNL3DATA d left join (select rownum as cislo from dual connect by rownum <= 400) numRows on d.id = d.id) b left join
( 
Select ID, F_SD + ROUND((ROUND((20 - F_DISTHASBEENCUT)/F_SAMPLELENGTH, 0) + (400 - (i_samplecount - ROUND((20 - F_DISTHASBEENCUT)/F_SAMPLELENGTH, 0) ) ) )/2, 0)-5 AS F_SD, val
FROM tm_hp_r_qnl3profcharts
      UNPIVOT INCLUDE NULLS 
( val  for (F_SD) IN
    (
      f_sd001   AS  1,
      ....
      f_sd400   AS  400
    )
  )  
  where i_charttypeid = 1 AND F_SD between ROUND((20 - F_DISTHASBEENCUT)/F_SAMPLELENGTH, 0) AND (i_samplecount - ROUND((20 - F_DISTHASBEENCUT)/F_SAMPLELENGTH, 0) ) 
  ) a on a.id = b.ID AND b.cislo = a.f_sd 
order by ID, F_SD

0 个答案:

没有答案