可以用元编程实现,其中 conds 是多个条件组成的列表:
unifiedCall(coalesce, loop(iif, conds, choices, NULL)).nullFill!(default)
请问类似np.select()多条件的怎么写? Sql中可以用case when,我想了解一下dos语言有没有对应的实现?如果条件的个数是不确定的,无法使用case...when,而需要使用coalesce。
我用q的话会这样写,不清楚ddb有没有现成的函数:
def^(^/)?'[conds;choices;nil]
这个直译成ddb的话,或许可以这样写:unifedCall(coalesce, iif:E(conds. choices, nil).matrix2tuple()).nullFill(nil)
其中就差矩阵到tuple的这部转换,或是对矩阵做类似coalesce的操作