-2
我有3列與id,level1,level2.I需要得到關於id的level1和level2的平均值.Same Id有多個level1和level2。在mysql中獲取某些條件的行的平均值
我試圖獲得獨特的行id..but平均我couldnt。
+--------+----------+-----------+
| id | level1 | level2 |
+--------+----------+-----------+
| 1 | 2 | 4 |
+--------+----------+-----------+
| 1 | 3 | 5 |
+--------+----------+-----------+
| 1 | 1 | 4 |
+--------+----------+-----------+
| 2 | 3 | 5 |
+--------+----------+-----------+
| 2 | 4 | 2 |
+--------+----------+-----------+
| 2 | 5 | 3 |
+--------+----------+-----------+
我需要像這樣的輸出。
+--------+----------+-------------------+
| id | avg_level1 | avg_level2 |
+--------+----------+-----------+--------
| 1 | 2 | 4.33 |
+--------+----------+-----------+-------+
| 2 | 4 | 3.33 |
+--------+----------+-----------+--------