如何在 KDB 中 return 以特定前缀开头的列?

How do I return columns starting with a particular prefix in KDB?

比如说我有一个 table:

q)([] aa: til 5; ab: til 5; bb: til 5)

aa ab bb
--------
0  0  0
1  1  1
2  2  2
3  3  3
4  4  4

是否有一种简单的方法来查询以 a 开头的列?

您可以使用函数 select

?[t;();0b;{x!x}cols[t] where cols[t] like "a*"]

https://code.kx.com/q/basics/funsql/

如果您的 table 在内存中并且未加密,那么 take (#) 也可以为您完成:

{where[c!(c:cols x)like"a*"]#x}t

但 Matts 的解决方案更通用,因此更有用!