在这里,作者封装了一个函数,fillNa_vvb(data,method),实现对表格data所有列中缺失值(nil)进行填充,支持前填,后填及自定义值填充。其参数:
//join无法实现列的合并,只能先合并主键序列后,再进行表连接
A:=array(('date':20190520T,'A1':11),
('date':20190521T,'A1':8),
('date':20190528T,'A1':2),
('date':20190530T,'A1':-1)
);
B:=array(('date':20190520T,'B1':3),
('date':20190521T,'B1':4),
('date':20190522T,'B1':2),
('date':20190523T,'B1':1),
('date':20190524T,'B1':6),
('date':20190527T,'B1':7),
('date':20190529T,'B1':8),
('date':20190530T,'B1':9)
);
C:=`array('date':A[:,'date'] union2 B[:,'date']);
//注:C表放到最后,为避免被A,B表中的空值覆盖
D:= select [2].*,[3].*,[1].*
from C full join A on [1].['date']=[2].['date']
full join B on [1].['date']=[3].['date']
order by [1].['date'] end;
return D;
//返回表格:
date | A1 | B1
|
---|
2019-05-20 | 11 | 3
|
2019-05-21 | 8 | 4
|
2019-05-22 | | 2
|
2019-05-23 | | 1
|
2019-05-24 | | 6
|
2019-05-27 | | 7
|
2019-05-28 | 2 |
|
2019-05-29 | | 8
|
2019-05-30 | -1 | 9
|
//对场景中的D表进行操作
//访法1:调用mfind实现
mfind(D,ifnil(mcell),nil,'-');
return D;
//方法2:调用fillNa_vvb实现
return fillNa_vvb(D,'-');
//或用 return return fillNa_vvb(D);
//返回表格:
date | A1 | B1
|
---|
2019-05-20 | 11 | 3
|
2019-05-21 | 8 | 4
|
2019-05-22 | - | 2
|
2019-05-23 | - | 1
|
2019-05-24 | - | 6
|
2019-05-27 | - | 7
|
2019-05-28 | 2 | -
|
2019-05-29 | - | 8
|
2019-05-30 | -1 | 9
|
//对场景中的D表进行操作
//方法1:
D::begin
if ifnil(mcell) then
mcell:=D[mrow-1][mcol];
end;
return D;
//方法2:
cstr:=mcols(D,1);
for i:=0 to length(cstr)-1 do
update D set [cstr[i]]=refof([cstr[i]],1) where ifnil([cstr[i]]) end;
return D;
//方法3:
return fillNa_vvb(D,'ffill');
//返回表格:
date | A1 | B1
|
---|
2019-05-20 | 11 | 3
|
2019-05-21 | 8 | 4
|
2019-05-22 | 8 | 2
|
2019-05-23 | 8 | 1
|
2019-05-24 | 8 | 6
|
2019-05-27 | 8 | 7
|
2019-05-28 | 2 | 7
|
2019-05-29 | 2 | 8
|
2019-05-30 | -1 | 9
|
//对场景中的D表进行操作
return fillNa_vvb(D,'bfill');
//返回表格:
date | A1 | B1
|
---|
2019-05-20 | 11 | 4
|
2019-05-21 | 8 | 4
|
2019-05-22 | 2 | 2
|
2019-05-23 | 2 | 1
|
2019-05-24 | 2 | 6
|
2019-05-27 | 2 | 7
|
2019-05-28 | 2 | 8
|
2019-05-29 | -1 | 8
|
2019-05-30 | -1 | 9
|