I would like to perform a query in Q/KDB that retrieves rows the fulfills the following criteria.
- Rows with the same name in a month must only have completed marked.
- Names should be distinct i.e. if they fulfill condition 1, they should only appear as a singular entry.
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.