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数据库未解之谜,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。