I have a table contains data of year and value. I'd like to create a cross table with all the year as column headings and calculate descriptive statistics in the rows.
For instance, I'd like to calculate the mean and median value for year 2005, 2006, and 2007 separately and put them in the following table format.
2005 2006 2007
Median
Mean
To calculate the median and mean for year 2005, the code would be:
SELECT avg(vallue),percentile_cont(0.5) WITHIN GROUP (ORDER BY value)
FROM tablename WHERE year=2005;
but I don't know how to turn it into a table