Reputation: 25
I am trying to teach myself kdb/q programming. I can't seem to figure out how to take a simple table (columns symbol
, price
, and shares
) and multiply price * shares
to get volume
. I've read Q for Mortals, code.kx.com, etc and am stuck. Could someone please give me a hint or point me in a direction of where I could figure out this simple problem! Thanks
Upvotes: 1
Views: 2060
Reputation: 3229
checkout the q-sql for select/update queries.
Here is the update
statement you are after:
q)trade:([] symbol:5?`APPL`GOOG; price:5?100.; shares:5?10)
q)update volume:price*shares from trade
symbol price shares volume
-------------------------------
APPL 21.09 6 126.54
APPL 88.22095 8 705.7676
APPL 25.0192 4 100.0768
GOOG 51.68842 1 51.68842
APPL 53.8142 8 430.5136
However, I'll recommend checking Q for mortals, it pretty much covers everything for Kdb+ beginner.
Upvotes: 3
Reputation: 251
Where t is the table name:
update volume: price*shares from t
Or
t: select symbol, price, shares, volume:price*shares from t
Upvotes: 7