Advertisement
Guest User

KDB Q Code for Pivot Table

a guest
Sep 14th, 2013
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
q/kdb+ 1.44 KB | None | 0 0
  1. MacBook-Pro:m32 xbsd$ ./q
  2. KDB+ 3.1 2013.09.05 Copyright (C) 1993-2013 Kx Systems
  3. m32/ 4()core 16384MB xbsd macbook-pro.local 192.168.1.2 PLAY 2013.12.04
  4.  
  5. q)n:5000000
  6. q)sym:`a`b`c`d`e`f`g`h`i`j`k`l`m`n`o`p`q`r`s`t
  7. q)t:([]col1:n?1000;col2:n?1000; col3:n?1000; grp:n?sym)
  8. q)s:sym
  9.  
  10. q)\t exec s#(grp!col4) by col1:col1,col2:col2 from update col4:sum col3 by col1,col2,grp from t
  11. 11865
  12. q)select[10] from exec s#(grp!col4) by col1:col1,col2:col2 from update col4:sum col3 by col1,col2,grp from t
  13. col1 col2| a   b   c   d   e    f g    h    i    j   k   l   m   n   o   p   ..
  14. ---------| ------------------------------------------------------------------..
  15. 0    0   |                                           662             977     ..
  16. 0    1   |         881     16     313       1544 943     291         623     ..
  17. 0    2   |                                                       336         ..
  18. 0    3   |         533            674  1637          658                     ..
  19. 0    4   |                 1362                          338         178 322 ..
  20. 0    5   |         557                 758                   84      936     ..
  21. 0    6   |         776 519        1516                       287             ..
  22. 0    7   | 906 239                     293                                   ..
  23. 0    8   |                 829              19                               ..
  24. 0    9   |             663             551                           814     ..
  25. q)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement