MS SQL 服务器数据库。
我有这个简单的结构:(抱歉主键不在正确的位置)
在 TEACHER 表中,我有一个外键“Chief”,它引用 TEACHER.ID(同一张表)。在进行 SELECT 查询时,如何获取不是整数(Teacher.ID),而是一个酋长的姓名(TEACHER.Name for Chief)?
这个只得到一个整数(酋长的 ID):
SELECT DEPARTMENT.Name, TEACHER.Name, TEACHER.IDCode, POST.Name, TEACHER.Tel, TEACHER.Salary, TEACHER.Rise, TEACHER.HireDate, Chief
FROM TEACHER, DEPARTMENT, POST
WHERE TEACHER.ID_Post = POST.ID AND
TEACHER.ID_Department = DEPARTMENT.ID;
GO