In my table i want to get the average value of two columns PackerID HeaderID Price Quantity Size 1 1 10 10 50 2 1 10 10 60 3 1 8.5 20 50 Price is per 1 quantity* from above table i want to get average price of Size '50' using PIVOTE.
If you look at the [PIVOT documentation], you'll see that one of the examples is an AVERAGE pivot. If you can build an intermediate table with the unpivoted data, then feed that into the PIVOT, you should be fine. If you want more help, then you'll need to explain exactly what you want and how you want it calculated... :
Why use `pivot`? I can get the average per size using a aggregate windowing function declare @t table (packerid int, price decimal(8,2), quantity int, size int) insert into @t select 1,10,10,50 insert into @t select 2,10,10,60 insert into @t select 3,8.5,10,50 select distinct size, avg(price)over(partition by size) from @t gives 50 9.250000 60 10.000000