0

有人可以帮我为什么这个查询,

select Fname, Lname from EMPLOYEE where not exists ((select Pnumber from PROJECT where Dnum=5) except (select Pno from WORKS_ON where EMPLOYEE.Ssn=Essn));

给我错误信息,

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'except (select Pno from WORKS_ON where EMPLOYEE.Ssn=Essn))' at line 1

这让我很困惑,因为

select Pnumber from PROJECT where Dnum=5

没有给我任何错误信息。我在制作 UNIVERSITY 数据库的书中遵循了示例。

mysql> show columns from EMPLOYEE;
+-----------+---------------+------+-----+---------+-------+
| Field     | Type          | Null | Key | Default | Extra |
+-----------+---------------+------+-----+---------+-------+
| Fname     | varchar(15)   | NO   |     | NULL    |       |
| Minit     | char(1)       | YES  |     | NULL    |       |
| Lname     | varchar(15)   | NO   |     | NULL    |       |
| Ssn       | char(9)       | NO   | PRI | NULL    |       |
| Bdate     | date          | YES  |     | NULL    |       |
| Address   | varchar(30)   | YES  |     | NULL    |       |
| Sex       | char(1)       | YES  |     | NULL    |       |
| Salary    | decimal(10,2) | YES  |     | NULL    |       |
| Super_ssn | char(9)       | YES  | MUL | NULL    |       |
| Dno       | int(11)       | NO   |     | NULL    |       |
+-----------+---------------+------+-----+---------+-------+

mysql> show columns from PROJECT;
+-----------+-------------+------+-----+---------+-------+
| Field     | Type        | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| Pname     | varchar(15) | NO   | UNI | NULL    |       |
| Pnumber   | int(11)     | NO   | PRI | NULL    |       |
| Plocation | varchar(15) | YES  |     | NULL    |       |
| Dnum      | int(11)     | NO   | MUL | NULL    |       |
+-----------+-------------+------+-----+---------+-------+

mysql> show columns from WORKS_ON;
+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| Essn  | char(9)      | NO   | PRI | NULL    |       |
| Pno   | int(11)      | NO   | PRI | NULL    |       |
| Hours | decimal(3,1) | NO   |     | NULL    |       |
+-------+--------------+------+-----+---------+-------+
4

1 回答 1

0

您可以像这样更改您的查询

select
  Fname,
  Lname
from EMPLOYEE
where not exists(select
           Pnumber
         from PROJECT
         where Dnum = 5)
     OR EMPLOYEE.Ssn IN(select
                 Pno
                   from WORKS_ON
                   where EMPLOYEE.Ssn = Essn)
于 2013-04-26T08:09:55.060 回答