You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何高效筛选多表动态列中无空值的行(含数值列表类型)

Q语言多表多列空值行过滤实现

背景代码

tab1:update volume:0n from ([] date:2024.01.01+til 10;sym:10?`appl`msgt`googl;volume:10#(enlist 0.5+300?til 100);price:10?10.5) where i in (1;5;8);

tab2:update price:0n from ([] date:2024.01.01+til 10;sym:10?`appl`msgt`googl;spread:10#(enlist 0.5+300?til 100);price:10?10.5) where i in (1;5;8);

// 待检查列配置
checkList:(`tab1;`volume`price);(`tab2;`spread`price);

需求说明

需高效检查指定表的指定列是否存在空值,只要指定列中任意一列存在空值则排除该行。支持任意数量的表与列,列类型可为int、float、int列表、float列表。示例逻辑:select from tab1 where not null volume & not null price(其中volume为float列表类型,price为float类型)。

解决方案

通用过滤函数

以下函数可接收单组(表名,列名列表)参数,返回过滤后不含空值行的表:

filterNullRows:{[tblName;cols]
  // 生成所有列非空的与条件
  filterCond:&/[not null each cols];
  // 执行查询并返回结果
  select from get[tblName] where filterCond;
}

批量处理多表

基于上述函数,遍历待检查配置列表即可批量处理所有表:

// 批量执行过滤,结果存储在resultList中,顺序与checkList对应
resultList:filterNullRows each checkList;

// 若需直接覆盖原表,可使用以下代码
{[tbl;cols] @[.;tbl;:;filterNullRows[tbl;cols]]} each checkList;

关键说明

  • 函数支持普通数值类型(int/float):null会检查值是否为0N(空值)
  • 函数支持列表类型(int列表/float列表):null会检查列表是否为0N[](空列表)
  • 若需求改为列表中不能包含任何空元素,可将过滤条件修改为&/[not any null each cols]

内容的提问来源于stack exchange,提问作者BlackPearl

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 04:46:16