I would like to perform a query in Q/KDB that retrieves rows the fulfills the following criteria.
Initial Table:
completed name month
--------------------
yes x 1
no x 1
yes y 2
yes y 2
no a 3
yes a 4
yes b 4
no b 4
no b 4
yes y 5
Initial Table Divvied Up by Months
completed name month
--------------------
yes x 1
no x 1
---------------------
yes y 2
yes y 2
--------------------
no a 3
--------------------
yes a 4
yes b 4
no b 4
no b 4
--------------------
yes y 5
Resultant Table:
completed name month
--------------------
yes y 2
yes a 4
yes y 5
Explanation:
In month 1, only x transacted but has not completed one deal, hence it is not in our final table.
In month 2, only y transacted with both deals being completed, hence it is in our final table.
In month 3, only a transacted but the deal is not completed.
In month 4, both a and b transacted, but since b has uncompleted deals, it is left out.
In month 5, only y transacted, so it is added to the final table.
Hi Carrein you can use the following using the each right adverb and the fby filter
distinct select from tab where ({all`yes=/:x};completed)fby([]name;month)
Additionally you might want to make use of a Boolean vector for the completed column for simplicity