我只是想看一个员工名单,如果他们是主管,他们旁边会有一个YES或NO。这是ANSI SQL不是一个实现(我认为这就是你所说的)。我正在测试命令: http://edu.konagora.com/SQLsandbox.php#
以下是我提出的建议:
SELECT firstname, lastname, CAST
(
CASE
WHEN Empl_ID IN (SELECT Empl_ID FROM Supervisor)
THEN "YES"
ELSE "NO"
END AS varchar(3)
) AS 'ISS'
FROM Employee;
我得到:(在Konagora.edu上)
SQL Error: no such table: array
表:
CREATE TABLE Supervisor
(
Super_ID mediumint not null auto_increment,
Empl_ID mediumint not null
);
CREATE TABLE Employee
(
Empl_ID mediumint not null auto_increment,
firstname varchar(100) not null,
lastname varchar(100) not null,
salary mediumint not null
);
答案 0 :(得分:2)
除了关于单引号和双引号的其他注释说明之外,你最好还是对主管表进行LEFT JOIN。
SELECT
E.firstname,
E.lastname,
case when S.Empl_ID IS NULL then 'NO' else 'YES' end as Iss
from
Employee E
LEFT JOIN Supervisor S
on E.Empl_ID = S.Empl_ID