question on the best way to do this

i've a table with timestamp, symbol, askPrice1,askPrice2, AskQty1,AskQty2 ...

and we will need to output to the following cols,

select askPrice1 *askQty1 , askPrice2*askQty2 ... askPrice50*askQty50 from table

is there any inbuilt functions we can use or any optimal way to calculate on dolphinDB?

thanks!

请先 登录 后评论

3 个回答

wale

select askPrice1 *askQty1 , askPrice2*askQty2 ... askPrice50*askQty50 from table. This is already the optimal way.

请先 登录 后评论
Alex - dba
cols = array(ANY, 50)
for(i in 0:50)
         cols[i] = sqlColAlias(expr(sqlCol("askPrice" + i), *, sqlCol("askQty" + i)), "tradeVol" + i)
sql(select = cols, from = t).eval()
请先 登录 后评论
blliu

假设有一个表如下:

t = table(10:0, ("askPrice" + string(1..50)) join ("AskQty" + string(1..50)), take(DOUBLE, 100));

可以用以下方式实现

sql(sqlColAlias(binaryExpr(sqlCol("askPrice" + string(1..50)), sqlCol("AskQty" + string(1..50)), *), "tradeVol" + string(1..50)), t).eval();
请先 登录 后评论