Pivoting with an extra field

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
fmou
Participant
Posts: 124
Joined: Sat May 28, 2011 9:48 pm

Pivoting with an extra field

Post by fmou »

Hi,

This example explains what I want to pivot:

Code: Select all

        Table 1. Simple pivot operation - input data
+-----------------------------------------------------------+
|   REPID   | last_name | Jan_sales | Feb_sales | Mar_sales |
|-----------+-----------+-----------+-----------+-----------|
| 100       | Smith     | 1234.08   | 1456.80   | 1578.00   |
|-----------+-----------+-----------+-----------+-----------|
| 101       | Yamada    | 1245.20   | 1765.00   | 1934.22   |
+-----------------------------------------------------------+
      Table 2. Simple pivot operation - output data
+--------------------------------------------------------+
|    REPID    |  last_name  | Pivot_desc   |   Q1sales   |
|-------------+-------------+--------------+-------------|
| 100         | Smith       | Jan_sales    | 1234.08     |
|-------------+-------------+--------------+-------------|
| 100         | Smith       | Feb_sales    | 1456.80     |
|-------------+-------------+--------------+-------------|
| 100         | Smith       | Mar_sales    | 1578.00     |
|-------------+-------------+--------------+-------------|
 . . . 
How can I do that?

Thanks
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Add in three "Pivot_desc" fields to the link and hard-code them to your values, pivot those along with the sales columns.
-craig

"You can never have too many knives" -- Logan Nine Fingers
fmou
Participant
Posts: 124
Joined: Sat May 28, 2011 9:48 pm

Post by fmou »

thanks! Didn't know how 2 pivoted columns correlate with each other.

Is it possible, for the 2 pivoted columns to pivot on different number of fields?

Thanks
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

REPID|last_name|Jan_sales|Feb_sales|Mar_sales|Jan_desc|Feb_desc|Mar_desc
100|Smith|1234.08|1456.80|1578.00|'Jan_sales'|'Feb_sales'|'Mar_sales'

REPID (key)
LAST_NAME (key)
PVTDESC: Jan_desc,Feb_desc,Mar_desc
Q1SALES: Jan_sales,Feb_sales,Mar_sales
-craig

"You can never have too many knives" -- Logan Nine Fingers
fmou
Participant
Posts: 124
Joined: Sat May 28, 2011 9:48 pm

Post by fmou »

Didn't know how 2 pivoted columns correlate with each other.
Hold on -- I replied before I try it, BUT it turns out that I was right. There is no correlation between the 2 pivoted columns, at least my results appears to me so.

What I am missing?

Thanks
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Sorry but I have no idea what you are trying to say here. If you've tried something and not gotten the results you needed, explain to us what you tried and what you ended up with.
-craig

"You can never have too many knives" -- Logan Nine Fingers
fmou
Participant
Posts: 124
Joined: Sat May 28, 2011 9:48 pm

Post by fmou »

Sorry, I was wrong -- working at midnight is not good for thinking.

Thanks
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

8)

Sometimes a fresh brain works wonders. And no, that's not a Young Frankenstein quote.
-craig

"You can never have too many knives" -- Logan Nine Fingers
dsedi
Participant
Posts: 220
Joined: Wed Jun 02, 2004 12:38 am

Post by dsedi »

Pivot/Pivot enterprise stage noob here :)
Post was helpful..Just want to say thanks to OP and Craig...
Accept that some days you're the pigeon and some days you're the statue.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Awesome. :D
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply