我有一张表,我需要根据日期列更新ID字段。
表A
import numpy as np
arr1 = [np.array([1, 2, 3]), np.array([1, 2]), np.array([2, 3])]
arr2 = [np.array([20, 50, 30]), np.array([50, 50]), np.array([75, 25])]
maxi = []
for i in range(len(arr1)):
maxi.append(np.max(arr1[i]))
maxi = np.max(maxi)
output = np.zeros((len(arr2),maxi))
for i in range(len(arr1)):
for k in range(len(arr1[i])):
output[i][k]=arr2[i][k]
表B
H_MEP_ID|_LoadDate |_EndDate |ID
12312 |2015-04-19 12:14:52.733 |2016-06-16 17:19:56.613 |72
12312 |2016-06-16 17:19:53.403 |NULL |83
更新脚本后表B的外观如何。
H_MEP_ID|MeasureDate|MeasureDateTime |ID
12312 |2015-10-02 |2015-10-02 23:00 |NULL
12312 |2015-11-01 |2015-11-01 23:00 |NULL
12312 |2015-11-02 |2015-11-02 23:00 |NULL
12312 |2016-06-16 |2016-06-16 23:00 |NULL
有人有任何建议如何进行?
表B有111M行,如何在MeasureDate字段上用while循环拆分查询?
答案 0 :(得分:0)
update b
set
b.id=a.id
from
tablea a
join
tableb b
on
b.H_MEP_ID=a.H_MEP_ID
and b.meaure_datetime between a.loaddate and isnull(a.enddate,getdate())