If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Can this be done??? Multiple rows to Multiple Columns

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-13-11, 15:04
dockraz dockraz is offline
Registered User
 
Join Date: Mar 2010
Posts: 12
Can this be done??? Multiple rows to Multiple Columns

I have a table that holds 3 fields:

PartNumber ( Char 25 )
Date ( Char 6 )
QtySold ( Integer )

The date is a representation of month year ( so 012011 would mean Jan 2011 ).

So a sample would be

A | 122010 | 5
A | 112010 | 4
A | 092010 | 7
A | 082010 | 6
B | 112010 | 5
B | 102010 | 4
B | 072010 | 7
B | 062010 | 6
C | 122010 | 5
C | 102010 | 11
C | 082010 | 9
C | 062010 | 3


What I need to see is 1 row for Part A - that shows all items - one row for b etc...

I can think of doing this manually with a bunch of case entries ( for each month )

But i'm wondering if there is an easier way...

What I want as a result is something like either:
Code:
A | 122010 | 5 | 112010 | 4 | 092010 | 7 | 082010 | 6
B | 112010 | 5 | 102010 | 4 | 072010 | 7 | 062010 | 6
C | 122010 | 5 | 102010 | 11 | 082010 | 9 | 062010 | 3
OR
Code:
# | 122010 | 112010 | 102010 | 092010 | 082010 | 072010 | 062010 |
A | 5      | 4      | 0      | 7      | 6      | 0      | 0      |
B | 0      | 5      | 4      | 0      | 0      | 7      | 6      |
C | 5      | 0      | 11     | 0      | 9      | 0      | 3      |
Any help is greatly appreciated!

Chris
Reply With Quote
  #2 (permalink)  
Old 01-13-11, 15:08
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
Quote:
Originally Posted by dockraz View Post
Can this be done??? Multiple rows to Multiple Columns
can this be done??? not easily, no

should this be done??? not in SQL, no
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On