上述脚本,在 DolphinDB 会按行取出赋值,每个变量都是一个字典,如:
t = table(['a', 'b', 'c'] as sym, [1, 2, 3] as val) res_a, res_b, res_c = select * from t where sym in ['a', 'b', 'c'] res_a // output val->1 sym->'a'
如果要实现 name = 'a' 赋值给 res_a, name = 'b' 赋值给 res_b...的效果,可以参考下述脚本:
t = table(`a`c`b`a`b`c as sym, 1 2 3 4 5 6 as value) def mysql_test(col): select * from t where sym in col res_a, res_b, res_c=each(mysql_test, [`a,`b,`c])
此处是利用了 each 遍历每个元素计算的特性,对每个分组单独进行查询并返回结果。