I have a table Pet.Info like the following in SQL Server :
pet age ...
--------------------
dog 4
cat 3
pig 2
dog 3
...
Now, I want to convert it into a table to calculate the average ages of dog and cat, and the average of all the others. Like the following:
dog cat others
-------------------------
3.5 3 2
Is it possible to do it with PIVOT?
Here is what I have get, but there seems no way to make it for the column of others
SELECT * FROM
(SELECT * FROM Pet.Info) AS B
PIVOT (AVG(age) FOR pet IN ([dog],[cat])) AS C
Thanks for advises in advance.
Try this: