[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

MySQL - Product a PIVOT resultset

Hi,
Is there a way  to generate a PIVOT resultset with Select Statement from MySQL as it the case with MS SQL?

Regards
0
Omer-Pitou
Asked:
Omer-Pitou
  • 3
3 Solutions
 
arnoldCommented:
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
 
Omer-PitouAuthor Commented:
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
 
arnoldCommented:
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
 
arnoldCommented:
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now