KX Community

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

Home Forums kdb+ Running Entry Count

  • Running Entry Count

    Posted by Laura on April 6, 2022 at 12:00 am

    Hey Qbies,

    I have a table containing for multiple symbols that I’m looking to count rows…

    For example:

    symbol | symbol count | dataset count
    
    aapl | 1 | 1
    
    aapl| 2 | 2
    
    goog| 1 | 3 
    
    
    

    Basically, I want to get identify the row count by symbol and then by dataset. I know that I can just grab “i” to get the rowcount for the dataset, but I’m having trouble pulling a symbol count

    Thanks!

    Laura replied 8 months ago 1 Member · 2 Replies
  • 2 Replies
  • Laura

    Administrator
    April 6, 2022 at 12:00 am

    sums i=i by sym

    did the trick

  • Laura

    Administrator
    April 7, 2022 at 12:00 am

    Not entirely clear what youre looking for here. If you want to produce a 1N list for each symbol you can use til and avoid the sums and comparisons:

     

    q)select 1+til count i by sym from t 
    sym | x 
    ----| --------------- 
    aapl| 1 2 3 4 5 
    goog| 1 2 3 4 5 6 7 8 
    msft| 1 2 3 4 5 6 7

     

    but its hard to see a use for the lists. Perhaps you simply want to count rows for each symbol?

    q)exec count i by sym from t 
    aapl| 5 
    goog| 8 
    msft| 7 
    
    q)ts:1000 select sums i=i by sym from t 4 10720
    q)ts:1000 exec count i by sym from t 1 9584

     

     

Log in to reply.