Search code examples
kdb

How can I select the last element of a kdb table for a set of unique column combinations?


I have this kdb table:

ts              ticker eid          bid     ask
--------------------------------------------------
09:30:00.001    TIF    NASDAQ       781700  792500
09:30:00.001    MRVL   BATSX        114500  118200
09:30:00.001    AVP    BATSX        239100  240100
09:30:00.001    AVP    ARCA         238000  239900
09:30:00.002    TIF    ARCA         780400  790400
09:30:00.002    AVP    BATSX        239100  239800
09:30:00.003    TIF    NYSE         783700  784000
09:30:00.003    TIF    ARCA         783400  790400
09:30:00.004    AVP    NYSE         239300  240000
09:30:00.004    TIF    NASDAQ       783500  792500
09:30:00.006    MRVL   BATSX        114500  117600
..

How can I select the last row of each ticker,eid pair? For this subset that would be:

09:30:00.001    AVP    ARCA         238000  239900
09:30:00.002    AVP    BATSX        239100  239800
09:30:00.003    TIF    NYSE         783700  784000
09:30:00.003    TIF    ARCA         783400  790400
09:30:00.004    AVP    NYSE         239300  240000
09:30:00.004    TIF    NASDAQ       783500  792500
09:30:00.006    MRVL   BATSX        114500  117600

Solution

  • Select without column list does this by default:

    select by ticker,eid form t