having子句中的未知列ename

6ie5vjzr  于 2021-06-24  发布在  Mysql
关注(0)|答案(2)|浏览(426)
MariaDB [testingcampus]> select * from employee;

+-----+--------+-----------+--------+
| EID | Ename  | City      | salary |
+-----+--------+-----------+--------+
| 100 | smith  | Bangalore |  10000 |
| 101 | carl   | Bangalore |  12000 |
| 102 | Ram    | Chennai   |  12000 |
| 103 | pankaj | Hyderabad |   5000 |
| 104 | vikram | Pune      |   2000 |
+-----+--------+-----------+--------+
5 rows in set (0.00 sec)

对于上表,当我键入下面的代码时,我得到一个错误

MariaDB [testingcampus]> Select eid from employee having ename= "Vikram";
ERROR 1054 (42S22): Unknown column 'ename' in 'having clause'
mw3dktmi

mw3dktmi1#

从http://www.mysqltutorial.org/mysql-having.aspx:
having子句在select语句中用于为一组行或聚合指定筛选条件。
你没有聚合,所以试试 WHERE 而不是 HAVING .

pdtvr36n

pdtvr36n2#

这是因为你不知道´不必使用having(它仅用于聚合函数),必须在以下情况下使用:

Select eid 
 from employee 
 where ename= "Vikram";

相关问题