Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
jeusdi
Starting Member
27 Posts |
Posted - 2006-10-05 : 10:41:18
|
Hello, I have a sentence how this:SELECT NUM_FIGURES, PERIMETER, PRICE FROM PRICE_LISTand the result is a "table" seems to: NUM_FIGURES PERIMETER PRICE 1 25 123 1 50 180 1 75 200 2 25 130 2 50 180 2 75 230,but I would like me get a "table" how: 25 50 75----------------------1 123 180 2002 130 180 230Does exist any form to get this type of "table" using SQL directly?Note: PRICE_LIST TABLE STRUCTURECREATE TABLE PRICE_LIST ( NUM_FIGURES INTEGER, PARIMETER INTEGER, PRICE REAL);Thanks for all in advanced |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-10-05 : 10:52:02
|
[code]select NUM, [25] = max(case when PERIMETER = 25 then PRICE end), [50] = max(case when PERIMETER = 50 then PRICE end), [75] = max(case when PERIMETER = 75 then PRICE end)from PRICE_LISTgroup by NUM[/code] KH |
|
|
jeusdi
Starting Member
27 Posts |
Posted - 2006-10-05 : 11:00:11
|
Exceuse me to forget a little big thing:25,50 and 75 can be any value, you can replaced them by x, y and z or a,b,c,d,e. Is my question possible? |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-10-05 : 11:03:07
|
quote: Originally posted by jeusdi Exceuse me to forget a little big thing:25,50 and 75 can be any value, You can be replaced by x, y and z or a,b,c,d,e. Is my question possible?
just replace with variableselect NUM, [col1] = max(case when PERIMETER = @x then PRICE end), [col2] = max(case when PERIMETER = @y then PRICE end), [col3] = max(case when PERIMETER = @z then PRICE end)from PRICE_LISTgroup by NUM KH |
|
|
jeusdi
Starting Member
27 Posts |
Posted - 2006-10-05 : 11:10:32
|
Mmm, for example: select NUM, [col1] = max(case when PERIMETER = @x then PRICE end), [col2] = max(case when PERIMETER = @y then PRICE end), [col3] = max(case when PERIMETER = @z then PRICE end) from PRICE_LIST group by NUMMy case is Mmm, for example: select NUM, [col1] = max(case when PERIMETER = @x then PRICE end), [col2] = max(case when PERIMETER = @y then PRICE end), [col3] = max(case when PERIMETER = @z then PRICE end) ... I don't know how much columns there are? from PRICE_LIST group by NUMAnd @x,@y,@z neither. They depends of supplier |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|