Jump to content

How to pivot rows into table colums


mabus

Recommended Posts

Hello, I'm having another mysql query problem, and this involves something like pivoting a query table.

 

Here's my example table..

 

YearMonth | TotalView | ViewType

2008-01      100            Type1

2008-02      200            Type2

2008-03      300            Type1

 

Now, what I want to achieve is that instead of having that "ViewType" column, I would want to have colums that are the values from that "ViewType" column. In other words, it will be two additional columns namely "Type1", and "Type2"... here's a sample result of what I would want...

 

 

YearMonth | Type1| Type2

2008-01      100      10 

2008-02      200      200

2008-03      300      300

 

Something like that.

 

The way I see it, I need to do a pivot on the table rows, but I do not know how  to do that yet, and I haven't found a good tutorial for it yet. So, if you have ideas on how I I may achieve this, please send your advices.

 

Thanks in advance

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.