gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 02:25:30 33 4
gpt4 key购买 nike

我有一个包含 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/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com