有人可以帮我解决这个问题,
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
没有给我任何错误消息。我在一本关于建立大学数据库的书中遵循了例子。
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 | |
+-------+--------------+------+-----+---------+-------+
答案 0 :(得分: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)