Solved

MySQL - Product a PIVOT resultset

Posted on 2015-01-14
4
164 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MySQL 11 79
Does PHPMyAdmin pose a security risk? 2 87
SQL, Updating Statistics take too long for 60GB database 5 101
CheckListBox usage 3 48
Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

948 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now