一个表的列太多时,如何快速选取除了某些列的所有列

假设我的表如下,有6列

t = table(1..10 as col1, 1..10 as col2, 1..10 as col3, 1..10 as col4, 1..10 as col5, 1..10 as col6)
t

attachments-2022-11-6vX7LYuS636b36a76d56d.png我的查询需求是,不需要第一列和第二列外的所有列,请问有什么便捷的方法吗?我的实际使用场景是这个表有100多列,上述只是一个举例说明

请先 登录 后评论

1 个回答

Guangxi LI

可以使用DolphinDB元编程来实现,元编程教程链接:https://gitee.com/dolphindb/Tutorials_CN/blob/master/meta_programming.md

上述场景的具体例子如下

colNames = t.schema().colDefs.name
//假设不取col1、col2
select_cols = colNames[at(!(colNames in [`col1, `col2]))]
res = sql(sqlCol(select_cols), t).eval()

查看返回的结果res变量的内容如下

attachments-2022-11-FeKg4gbI636b37595b027.png

请先 登录 后评论