By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,985 Members | 1,861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,985 IT Pros & Developers. It's quick & easy.

Pleasehelp me with my problem in sql.. column to row

P: 1
Hi everyone,

Can someone please help me with my problem,

I really need to solve this...

I have a table Sales....

Product | Brand | Sales | Price_1| Price_2 | Price_3
---------------------------------------------------------
Milk | Alaska | 0 | 10 | 20 | 30
Milk | Alaska | 1 | 80 | 70 | 90
Milk | Alaska | 2 | 100 | 200 | 300



I need to get the minimum and maximum sales of each Product...

sales |
------
0 |
2 |


after that I need to put their prices as before and after as a row...

just like this
salesfor 0 sales for 2
bef Price | Aft Price
-------------------------
10 | 100 <-- Price 1
20 | 200 <-- Price 2
30 | 300 <-- Price 3

I want to have an output like this

Produt |Brand |MinSales |bef Price|MaxSales |Aft Price
-----------------------------------------------------
Milk |Alaska |0 | 10 |2 |100
Milk |Alaska |0 | 20 |2 |200
Milk |Alaska |0 | 30 |2 |300





Please help me with this problem




Thnk you so much in advance for anyhelp that you can do...
Aug 22 '12 #1
Share this Question
Share on Google+
1 Reply


Rabbit
Expert Mod 10K+
P: 12,349
Use a min and max aggregate query joined to the table to return the rows you need. Then use a union to normalize the data. Then finally join the result to itself on the min row to the max row.
Aug 22 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.