如何对price列按价位空缺的行补足

如下图所示,左表是输入,其price列有100,101,103,106,其中空缺 102,104,105。右表是输出,把左表空缺的行补上了,且其n值为0。

attachments-2023-01-VevtP0WV63b679e31ec62.png

请先 登录 后评论

1 个回答

levenew

可以建一个完整price列的表与原表进行左连接,再使用nullFill方法填充空值为0:

t=table(100 101 103 106 as price,take(10,4) as n)
t1=table(t.price.min()..t.price.max() as price)
select price,nullFill(n,0) as n from lj(t1,t,`price)

连接结果如下:

price	n
100	10
101	10
102	0
103	10
104	0
105	0
106	10



请先 登录 后评论