KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ Applying nested conditions in q Re: Applying nested conditions in q

  • cillianreilly

    Member
    September 23, 2021 at 12:00 am

    This is most easily done in two parts and then defaulting the rest to welcome:

     

    q)T:update newCol:`hi from T where a=`F,b<c 
    q)T:update newCol:`hi from T where a<>`F,c>d 
    q)T:update`welcome^newCol from T 
    q)T 
    a b c d newCol 
    ------------------ 
    F 10 9 10 welcome 
    R 20 21 22 welcome

     

    You may find the reference on update statements useful: https://code.kx.com/q/ref/update/

    If you want it done in one line (which doesn’t scale well for any additional clauses you might want):

     

    q)update newCol:`welcome`hi any(all(a=`F;b<c);all(a<>`F;c>d))from T 
    a b c d newCol 
    ------------------ 
    F 10 9 10 welcome 
    R 20 21 22 welcome