MYSQL数据库未解之谜

分组查询

正常情况

mysql> SELECT * FROM students ;

+-----+-------------+-----+--------+------------+---------+

| SID | Name        | Age | Gender | Tutor      | ClassID |

+-----+-------------+-----+--------+------------+---------+

|   1 | Guo Jing    |  27 | M      | Song Jing  |       2 |

|   2 | Yang Guo    |  28 | M      | Hu Sanning |       3 |

|   3 | Guo Polu    |  21 | M      | Jia Baoyu  |       3 |

|   4 | Xue Baochai |  19 | F      | Rong Momo  |       1 |

|   5 | Xia Yuhe    |  37 | F      | Shi Qian   |       2 |

|   6 | Wu Yong     |  51 | M      | Lin Daiyu  |       1 |

|   7 | tom         |  11 | M      | jerry      |       1 |

|   9 | tomy        |  13 | M      | NULL       |       4 |

+-----+-------------+-----+--------+------------+---------+

8 rows in set (0.00 sec)

mysql> SELECT * FROM students GROUP BY Gender;

+-----+-------------+-----+--------+-----------+---------+

| SID | Name        | Age | Gender | Tutor     | ClassID |

+-----+-------------+-----+--------+-----------+---------+

|   4 | Xue Baochai |  19 | F      | Rong Momo |       1 |

|   1 | Guo Jing    |  27 | M      | Song Jing |       2 |

+-----+-------------+-----+--------+-----------+---------+

2 rows in set (0.06 sec)

但是

mysql> SELECT SUM(Age) FROM students GROUP BY Gender HAVING Age > 25;

ERROR 1054 (42S22): Unknown column 'Age' in 'having clause'

居然报错了。。。




你可能感兴趣的:(mysql,select)