[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

MySQL - Product a PIVOT resultset

Posted on 2015-01-14
4
Medium Priority
?
186 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 80

Assisted Solution

by:arnold
arnold earned 1500 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 80

Assisted Solution

by:arnold
arnold earned 1500 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 80

Accepted Solution

by:
arnold earned 1500 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

649 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