KX Community

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

Home Forums kdb+ xbar millisecond

  • xbar millisecond

    Posted by powerpeanuts on September 9, 2022 at 12:00 am

    Hi,

    in the select statement, we can easily do 5 xbar time.minute to group the data for every 5 minutes, what is the equivalent for doing like every 5 millisecond?

    powerpeanuts replied 9 months, 2 weeks ago 4 Members · 3 Replies
  • 3 Replies
  • cillianreilly

    Member
    September 9, 2022 at 12:00 am

    If you don’t cast to minutes first, you can explicitly group by millisecond (assuming your time column is a timestamp):

    q)t:([]time:.z.p+500000*til 20;col:til 20) 
    q)select avg col by 5000000 xbar time from t // millisecond = 1000000 nanoseconds 
    time                         | col 
    -----------------------------| ---- 
    2022.09.09D03:50:38.425000000| 2.5 
    2022.09.09D03:50:38.430000000| 10.5 
    2022.09.09D03:50:38.435000000| 17.5
  • rocuinneagain

    Member
    September 9, 2022 at 12:00 am

    A timespan can be used directly

    q)select avg col by 0D00:00:00.005 xbar time from t 
    time                         | col 
    -----------------------------| ---- 
    2022.09.09D07:40:23.110000000| 3 
    2022.09.09D07:40:23.115000000| 11.5 
    2022.09.09D07:40:23.120000000| 18

     

  • sujoy

    Member
    September 11, 2022 at 12:00 am

    5 xbar `time$time

Log in to reply.