Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fliping data from result.

Status
Not open for further replies.

DarkWorlds

Technical User
Jul 20, 2005
64
US
Well I need to re-arrange my output in a way that works without doing 52 lef joins.

basicly the output is as follows.

store|week|profit

5|1|25000
5|2|15000
5|3|9850

Well I need the following
_____|week1 |week2 |
store|profit|profit|

How can I do this with a select and not do 52 left joins?
 
There are a few ways do to this but in pure SQL terms try this. It works because you know the number of weeks (52 presumably) in advance

select
store,
max(decode(week,1,profit,null)) wk1,
max(decode(week,2,profit,null)) wk2,
max(decode(week,3,profit,null)) wk3,
...
and so on until
...
max(decode(week,52,profit,null)) wk52
from t1
group by store



In order to understand recursion, you must first understand recursion.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top