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
https://forums.phpfreaks.com/topic/130376-how-to-pivot-rows-into-table-colums/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.