kdb+/q Pivot Table to Turn Multiple Columns into a Single Column?










2















Given the following table:



date acct sec qtya qtyb qtyc
----------------------------
11 1 xx 10 60 110
22 2 yy 20 70 120
33 3 zz 30 80 130
44 2 xx 40 90 140
55 3 yy 50 100 150


Created using this statement:



t:(date:11 22 33 44 55;acct:1 2 3 2 3;sec:`xx`yy`zz`xx`yy;qtya:10 20 30 40 50;qtyb:60 70 80 90 100;qtyc:110 120 130 140 150)


Give a way to return the data as follows:



date acct sec qty
-----------------
11 1 xx 10
11 1 xx 60
11 1 xx 110
22 2 yy 20
22 2 yy 70
22 2 yy 120
33 3 zz 30
33 3 zz 80
33 3 zz 130
44 2 xx 40
44 2 xx 90
44 2 xx 140
55 3 yy 50
55 3 yy 100
55 3 yy 150


Which can be created using this statement:



q)T:(date:11 11 11 22 22 22 33 33 33 44 44 44 55 55 55;acct:1 1 1 2 2 2 3 3 3 2 2 2 3 3 3;sec:`xx`xx`xx`yy`yy`yy`zz`zz`zz`xx`xx`xx`yy`yy`yy;qty:10 60 110 20 70 120 30 80 130 40 90 140 50 100 150)









share|improve this question




























    2















    Given the following table:



    date acct sec qtya qtyb qtyc
    ----------------------------
    11 1 xx 10 60 110
    22 2 yy 20 70 120
    33 3 zz 30 80 130
    44 2 xx 40 90 140
    55 3 yy 50 100 150


    Created using this statement:



    t:(date:11 22 33 44 55;acct:1 2 3 2 3;sec:`xx`yy`zz`xx`yy;qtya:10 20 30 40 50;qtyb:60 70 80 90 100;qtyc:110 120 130 140 150)


    Give a way to return the data as follows:



    date acct sec qty
    -----------------
    11 1 xx 10
    11 1 xx 60
    11 1 xx 110
    22 2 yy 20
    22 2 yy 70
    22 2 yy 120
    33 3 zz 30
    33 3 zz 80
    33 3 zz 130
    44 2 xx 40
    44 2 xx 90
    44 2 xx 140
    55 3 yy 50
    55 3 yy 100
    55 3 yy 150


    Which can be created using this statement:



    q)T:(date:11 11 11 22 22 22 33 33 33 44 44 44 55 55 55;acct:1 1 1 2 2 2 3 3 3 2 2 2 3 3 3;sec:`xx`xx`xx`yy`yy`yy`zz`zz`zz`xx`xx`xx`yy`yy`yy;qty:10 60 110 20 70 120 30 80 130 40 90 140 50 100 150)









    share|improve this question


























      2












      2








      2








      Given the following table:



      date acct sec qtya qtyb qtyc
      ----------------------------
      11 1 xx 10 60 110
      22 2 yy 20 70 120
      33 3 zz 30 80 130
      44 2 xx 40 90 140
      55 3 yy 50 100 150


      Created using this statement:



      t:(date:11 22 33 44 55;acct:1 2 3 2 3;sec:`xx`yy`zz`xx`yy;qtya:10 20 30 40 50;qtyb:60 70 80 90 100;qtyc:110 120 130 140 150)


      Give a way to return the data as follows:



      date acct sec qty
      -----------------
      11 1 xx 10
      11 1 xx 60
      11 1 xx 110
      22 2 yy 20
      22 2 yy 70
      22 2 yy 120
      33 3 zz 30
      33 3 zz 80
      33 3 zz 130
      44 2 xx 40
      44 2 xx 90
      44 2 xx 140
      55 3 yy 50
      55 3 yy 100
      55 3 yy 150


      Which can be created using this statement:



      q)T:(date:11 11 11 22 22 22 33 33 33 44 44 44 55 55 55;acct:1 1 1 2 2 2 3 3 3 2 2 2 3 3 3;sec:`xx`xx`xx`yy`yy`yy`zz`zz`zz`xx`xx`xx`yy`yy`yy;qty:10 60 110 20 70 120 30 80 130 40 90 140 50 100 150)









      share|improve this question
















      Given the following table:



      date acct sec qtya qtyb qtyc
      ----------------------------
      11 1 xx 10 60 110
      22 2 yy 20 70 120
      33 3 zz 30 80 130
      44 2 xx 40 90 140
      55 3 yy 50 100 150


      Created using this statement:



      t:(date:11 22 33 44 55;acct:1 2 3 2 3;sec:`xx`yy`zz`xx`yy;qtya:10 20 30 40 50;qtyb:60 70 80 90 100;qtyc:110 120 130 140 150)


      Give a way to return the data as follows:



      date acct sec qty
      -----------------
      11 1 xx 10
      11 1 xx 60
      11 1 xx 110
      22 2 yy 20
      22 2 yy 70
      22 2 yy 120
      33 3 zz 30
      33 3 zz 80
      33 3 zz 130
      44 2 xx 40
      44 2 xx 90
      44 2 xx 140
      55 3 yy 50
      55 3 yy 100
      55 3 yy 150


      Which can be created using this statement:



      q)T:(date:11 11 11 22 22 22 33 33 33 44 44 44 55 55 55;acct:1 1 1 2 2 2 3 3 3 2 2 2 3 3 3;sec:`xx`xx`xx`yy`yy`yy`zz`zz`zz`xx`xx`xx`yy`yy`yy;qty:10 60 110 20 70 120 30 80 130 40 90 140 50 100 150)






      kdb






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 21:41









      user2242865

      497412




      497412










      asked Nov 14 '18 at 4:07









      UllauriUllauri

      347510




      347510






















          2 Answers
          2






          active

          oldest

          votes


















          3














          Using flip :



          q)ungroup select date , acct, sec , qty: flip (qtya;qtyb;qtyc) from t





          share|improve this answer






























            2














            q)ungroup 3!select date,acct,sec,qty:(qtya,'qtyb,'qtyc) from t



            date acct sec qty
            -----------------
            11 1 xx 10
            11 1 xx 60
            11 1 xx 110
            22 2 yy 20
            22 2 yy 70
            22 2 yy 120
            33 3 zz 30
            33 3 zz 80
            33 3 zz 130
            44 2 xx 40
            44 2 xx 90
            44 2 xx 140
            55 3 yy 50
            55 3 yy 100
            55 3 yy 150





            share|improve this answer






















              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53293058%2fkdb-q-pivot-table-to-turn-multiple-columns-into-a-single-column%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              3














              Using flip :



              q)ungroup select date , acct, sec , qty: flip (qtya;qtyb;qtyc) from t





              share|improve this answer



























                3














                Using flip :



                q)ungroup select date , acct, sec , qty: flip (qtya;qtyb;qtyc) from t





                share|improve this answer

























                  3












                  3








                  3







                  Using flip :



                  q)ungroup select date , acct, sec , qty: flip (qtya;qtyb;qtyc) from t





                  share|improve this answer













                  Using flip :



                  q)ungroup select date , acct, sec , qty: flip (qtya;qtyb;qtyc) from t






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 14 '18 at 7:54









                  aliakaliak

                  5,88531436




                  5,88531436























                      2














                      q)ungroup 3!select date,acct,sec,qty:(qtya,'qtyb,'qtyc) from t



                      date acct sec qty
                      -----------------
                      11 1 xx 10
                      11 1 xx 60
                      11 1 xx 110
                      22 2 yy 20
                      22 2 yy 70
                      22 2 yy 120
                      33 3 zz 30
                      33 3 zz 80
                      33 3 zz 130
                      44 2 xx 40
                      44 2 xx 90
                      44 2 xx 140
                      55 3 yy 50
                      55 3 yy 100
                      55 3 yy 150





                      share|improve this answer



























                        2














                        q)ungroup 3!select date,acct,sec,qty:(qtya,'qtyb,'qtyc) from t



                        date acct sec qty
                        -----------------
                        11 1 xx 10
                        11 1 xx 60
                        11 1 xx 110
                        22 2 yy 20
                        22 2 yy 70
                        22 2 yy 120
                        33 3 zz 30
                        33 3 zz 80
                        33 3 zz 130
                        44 2 xx 40
                        44 2 xx 90
                        44 2 xx 140
                        55 3 yy 50
                        55 3 yy 100
                        55 3 yy 150





                        share|improve this answer

























                          2












                          2








                          2







                          q)ungroup 3!select date,acct,sec,qty:(qtya,'qtyb,'qtyc) from t



                          date acct sec qty
                          -----------------
                          11 1 xx 10
                          11 1 xx 60
                          11 1 xx 110
                          22 2 yy 20
                          22 2 yy 70
                          22 2 yy 120
                          33 3 zz 30
                          33 3 zz 80
                          33 3 zz 130
                          44 2 xx 40
                          44 2 xx 90
                          44 2 xx 140
                          55 3 yy 50
                          55 3 yy 100
                          55 3 yy 150





                          share|improve this answer













                          q)ungroup 3!select date,acct,sec,qty:(qtya,'qtyb,'qtyc) from t



                          date acct sec qty
                          -----------------
                          11 1 xx 10
                          11 1 xx 60
                          11 1 xx 110
                          22 2 yy 20
                          22 2 yy 70
                          22 2 yy 120
                          33 3 zz 30
                          33 3 zz 80
                          33 3 zz 130
                          44 2 xx 40
                          44 2 xx 90
                          44 2 xx 140
                          55 3 yy 50
                          55 3 yy 100
                          55 3 yy 150






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 14 '18 at 4:13









                          user2242865user2242865

                          497412




                          497412



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53293058%2fkdb-q-pivot-table-to-turn-multiple-columns-into-a-single-column%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              這個網誌中的熱門文章

                              How to read a connectionString WITH PROVIDER in .NET Core?

                              Museum of Modern and Contemporary Art of Trento and Rovereto

                              In R, how to develop a multiplot heatmap.2 figure showing key labels successfully