sql - 一次在 SQL 查询中选择 100 多个列(但不是所有表列)的便捷方法?

标签 sql metaprogramming dynamic-sql dolphindb

我有一个包含 100 多列的表,我想查询除第一列和第二列以外的所有列。如何在不枚举 100 列的情况下快速完成?

仅出于说明目的,假设我有这个包含 6 列的表格:

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

输出:

col1    col2    col3    col4    col5    col6
1       1       1       1       1       1
2       2       2       2       2       2
3       3       3       3       3       3

如何从表中选择除前 2 列以外的所有列?

最佳答案

您可能会发现 DolphinDB 元编程对您的情况有帮助 (metaprogramming technique in DolphinDB)。

继续你的例子,试试这个脚本:

colNames = t.schema().colDefs.name
// assuming you don't want col1 and col2
select_cols = colNames[at(!(colNames in [`col1, `col2]))]
res = sql(sqlCol(select_cols), t).eval()

打印资源:

col3    col4    col5    col6
1       1       1       1
2       2       2       2
3       3       3       3   

关于sql - 一次在 SQL 查询中选择 100 多个列(但不是所有表列)的便捷方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74567600/

相关文章:

Python 元编程 : generate a function signature with type annotation

r - {rlang }'s ' curly-curly'运算符 `{{`是如何实现的?

python - 在 python 中,我们可以在(其他)用户代码执行之前跟踪模块级分配吗?

postgresql - 我可以在 PostgreSQL 触发器函数中迭代 NEW 吗?

sql - SQLite3中使用除法的计算字段

java - App Engine Java Servlet 不连接到 Cloud SQL

mysql - 仅选择与 IN 子句下指定的所有值匹配的那些行

sql - 按值的数量对列进行排名

sql - 如何从带参数的函数创建 View ?

sql - 从 SQL Server 数据库中选择任意范围的记录