在KDB我有这个表:
q)tab
items sales prices adjust factor
--------------------------------
nut 6 10 1b 1.2
bolt 8 20 1b 1.5
cam 0 15 1b 2
cog 3 20 0b 0n
nut 6 10 0b 0n
bolt 8 20 0b 0n
Run Code Online (Sandbox Code Playgroud)
我想根据条件计算第4列,例如:
if[adjust; prices * factor;]
Run Code Online (Sandbox Code Playgroud)
目的是获得以下结果:
items sales prices newPrices
----------------------------
nut 6 10 12
bolt 8 20 30
cam 0 15 30
cog 3 20 20
nut 6 10 10
bolt 8 20 20
Run Code Online (Sandbox Code Playgroud)
有人可以帮帮我吗?
小智 5
我想你正在寻找类似的东西:
q) update newPrices:?[adjust;prices*factor;prices] from tab
items sales prices adjust factor newPrices
------------------------------------------
nut 6 10 1 1.2 12
bolt 8 20 1 1.5 30
cam 0 15 1 1 15
cog 3 20 0 20
nut 6 10 0 10
bolt 8 20 0 20
Run Code Online (Sandbox Code Playgroud)