我有以下数据表和数据:
mysql> describe school_data_sets_numeric_data;
+--------------+----------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+----------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| data_set_nid | int(11) | NO | | NULL | |
| school_nid | int(11) | NO | | NULL | |
| year | int(11) | NO | | NULL | |
| description | varchar(255) | NO | | NULL | |
| value | decimal(18,12) | NO | | NULL | |
+--------------+----------------+------+-----+---------+----------------+
6 rows in set (0.00 sec)
+----+--------------+------------+------+-------------------+------------------+
| id | data_set_nid | school_nid | year | description | value |
+----+--------------+------------+------+-------------------+------------------+
| 54 | 19951 | 19944 | 2008 | Asian | 75.000000000000 |
| 51 | 19951 | 19944 | 2008 | White | 200.000000000000 |
| 52 | 19951 | 19944 | 2008 | African American | 100.000000000000 |
| 53 | 19951 | 19944 | 2008 | Hispanic | 50.000000000000 |
| 55 | 19951 | 19944 | 2008 | Native American | 9.000000000000 |
我想显示数据的平均值而不是原始数字。我想在原始 sql 中执行此操作。
例子:
+----+--------------+------------+------+-------------------+------------------+
| id | data_set_nid | school_nid | year | description | average |
+----+--------------+------------+------+-------------------+------------------+
| 54 | 19951 | 19944 | 2008 | Asian | 17.28% |
| 51 | 19951 | 19944 | 2008 | White | 46.06% |
| 52 | 19951 | 19944 | 2008 | African American | 23.04% |
| 53 | 19951 | 19944 | 2008 | Hispanic | 11.52% |
| 55 | 19951 | 19944 | 2008 | Native American | 2.07% |
做这个的最好方式是什么?请记住,会有多个数据集和年份。