如何计算一个表的各个列有多少NULL值?

计算一个表各个列有多少个NULL值,请问有便捷方式可以计算吗?

请先 登录 后评论

2 个回答

Qing Li
table(t.colNames() as name, each(x->x.size() - x.count(), t.values()) as nullCount)
请先 登录 后评论
Peter
// 方案一:使用 each 函数
table(t.colNames() as name, each(x->x.size() - x.count(), t.values()) as nullCount)

// 方案二:使用 isNull 函数
sum(t.isNull())

性能测试

数据量:10,000,000 行 x 3 列的表

测试方案:通过 timer 函数统计100次计算的耗时,计算单次平均耗时

测试结果

方案一:21.43ms

方案二:34.33ms

数据构造:

n = 10000000
id = rand(1 2 3 NULL, n)
name = rand(['a', 'b', 'c', NULL], n)
value = rand(1..10 join NULL, n)
t = table(id, name, value)
请先 登录 后评论
  • 2 关注
  • 0 收藏,1076 浏览
  • Jax Wu 提出于 2021-06-24 10:10