这是一个表1:
+--------------------+
| type | size | code |
+--------------------+
| A | 10 | 1 |
| A | 8 | 0 |
| B | 3 | 1 |
| B | 5 | 0 |
| A | 9 | 1 |
+--------------------+
现在我想创建一个视图来实现这些目标:
1. Group by "type" column
2. calculate avg(size) for each "type"
3. calculate the percent of "1" in "code" cloumn for "type"
+----------------------------+
| type | avg(size) | percent |
+----------------------------+
| A | 9 | 2/3 |
| B | 4 | 1/2 |
+----------------------------+
创建这样的视图的最佳方法是什么?