如何将一张表中部分列全为NULL的记录删除?

请问一下,一个透视表,怎样删除所有列都是空的行,除了code列。如下图:

attachments-2021-08-Rwy01yFq6119e4dd6f503.png

请先 登录 后评论

1 个回答

Johhny

构造内存表:

code = `01`02`03`04`05
col1 = 1 NULL 2 NULL NULL
col2 = 1 NULL NULL 3 4
col3 = 3 NULL 3 4 5
col4 = take(double(NULL), 5)
t = table(code, col1, col2, col3,  col4)

方法1:

colNames = t.schema().colDefs.name
vec_cols = colNames[at(!(colNames in [`code]))]

t[each(isValid, t[vec_cols]).rowOr()]

方法2:

colNames = t.schema().colDefs.name
vec_cols = colNames[at(!(colNames in [`code]))]

whereConditions = array(ANY, 0)
for(i in vec_cols) {
	whereConditions.append!(expr(sqlCol(i), ==, NULL))
}
sqlDelete(t, whereConditions).eval()
请先 登录 后评论