Hello, Newbie here. Is there a way that I can transpose DB rows into columns? I am thinking, that I can read the rows into a hashmap and then do some processing there, but am just not sure how to go about this.

For example: If I have the below table:

id name dept date_joined email date_sent 1 P1 Test 12/10/14 Y 12/11/14 10:53:45 1 P1 Test2 1/1/14 Y 1/05/14 05:25:34 2 P2 Test 3/1/14 N Null 2 P2 Test 8/1/14 Y 8/05/14 11:28:28 3 P2 Test3 10/1/14 N Null

Desired Output is: id name Test Test2 Test3 Y_email N_E +mail 1 P1 12/10/14,8/1/14 1/1/14,3/1/14 10/1/14 12/11/14 10:53:45 +,1/05/14 05:25:35,8/05/14 11:28:28 Null 2 P2 1/1/14,3/1/14 null 10/1/14 Null, Null Basically, trying to transpose and flatten it to get one row per recor +d. Any ideas how I can do this?

Can anyone suggest how I can go about this in the simplest way possible? The data I am dealing with is huge.

Thanks in advance


In reply to Transposing rows to columns by simak29

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.