Solved

MySQL - Product a PIVOT resultset

Posted on 2015-01-14
4
168 Views
Last Modified: 2015-01-29
Hi,
Is there a way  to generate a PIVOT resultset with Select Statement from MySQL as it the case with MS SQL?

Regards
0
Comment
Question by:Omer-Pitou
  • 3
4 Comments
 
LVL 77

Assisted Solution

by:arnold
arnold earned 500 total points
ID: 40550387
yes, you can use case or if to pull the data out.
There is no pivot table as in built in mechanism.


select column
if column reference check, value as column reference,
if column reference1 check, value as column reference1,
if column reference2 check, value as column reference2,

group by ...

if you post sample data, ............
0
 

Author Comment

by:Omer-Pitou
ID: 40550396
Here is a sample
ZipCode OrderNumber CustomerID ProductID OrderQty ...

I want to ZipCode in columns, ProductID in rows, and count(Qty) at the intersection.
0
 
LVL 77

Assisted Solution

by:arnold
arnold earned 500 total points
ID: 40550410
If I am not mistaken, pivot deals with extracting data in rows and displaying them in columns/

id, type, value
type can be  type1,type2,type3

the pivot would make
id type1 value ,type2 value ,type3 value

can you post an actual data sample

lets say you have

zipcode1,order1,customer1,product1,12
zipcode2,order2,customer2,product1,13

you want the result to be
product1,zipcode1,zipcode2,25
0
 
LVL 77

Accepted Solution

by:
arnold earned 500 total points
ID: 40550420
select productid, zipcode as "zipcode",sum(quantity) from tablename group by productid

The attempt is to convert the value in zipcode to be made the column name using the as.


Have not tested .....
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question