sxzhangzsx
sxzhangzsx

Reputation: 75

kdb update multiple columns corresponding to multiple where clauses

I have a table, which is :

t:([]a:1 3 2 1 2 3 3 2 1;b:10 20 30 40 50 60 70 80 90;c:100 200 300 400 500 600 700 800 900)

And I want all c to be 0 where a is equal to 2, and all be to be 0 where a is equal to 1.

Currently I have these two codes:

t:update b:0 from t where a=1

t:update c:0 from t where a=2

My question is how to combine these two lines of codes into one. Because I am working on a table which is far bigger than this simple example and it will take me a lot of rows of codes to do all the updates, which is too long.

Upvotes: 1

Views: 966

Answers (1)

MdSalih
MdSalih

Reputation: 1996

You can use vector conditional for this:

update b:?[a=1;0;b], c:?[a=2;0;c] from t

Upvotes: 2

Related Questions