Reputation: 1109
I have a mysql table with 3 columns named A, B, and C. Let a be a value from column A, b from column B. I want to create a new table with 4 columns having values a, b, mean of values of column C where A=a and B=b, variance of values of column C, where A=a and B=b. The new table will have as many rows as the number of unique (a,b) pairs. How to do this?
Upvotes: 0
Views: 918
Reputation: 169143
This query will fetch the values. You can use the MySQL INSERT INTO ... SELECT
syntax if you want to select the results into another table.
SELECT A, B, AVG(C) AS C_mean, VARIANCE(C) AS C_variance
FROM table_name
GROUP BY A, B
Upvotes: 4