简体   繁体   English

SQL Server Management Studio:不能绑定多部分标识符

[英]SQL Server Management Studio: The multi-part identifier could not be bound

I'm taking a SQL class, and on one of the assignments I am asked to create a table with employees, one with projects, as follows: 我正在上一个SQL类,在一项任务中,我被要求创建一个带有员工的表,一个带有项目的表,如下所示:

create table [EMPLOYEE]
(
    EmployeeID int identity(1, 1) primary key not null,
    FirstName varchar(15) not null,
    LastName varchar(15) not null,
    Gender char(1) not null,
    DOB date not null,
    SSN char(9) not null
)

create table [PROJECT]
(
    ProjectID int identity(1, 1) primary key not null,
    Manager int not null,
    PDescription varchar(50) not null,
    PStatus varchar(20) not null,
    StartDate date not null,
    EndDate date not null
)

Where the Manager is the ID of an EMPLOYEE entity. 其中ManagerEMPLOYEE实体的ID Basically projects are assigned to employees. 基本上,项目是分配给员工的。 So, I add some employees and projects 因此,我添加了一些员工和项目

insert into EMPLOYEE (FirstName, LastName, Gender, DOB, SSN)
values ('Chuck', 'Carter', 'M', '07/14/1990', '444556666')

This is the one employee I'm interested in, and in the inserting I'm doing this is the second one, so its EmployeeID would be 2. As for the projects: 这是我感兴趣的一位员工,在插入过程中我是第二位,因此它的EmployeeID为2。至于项目:

insert into PROJECT (Manager, PDescription, PStatus, StartDate, EndDate)
values (2, 'Submit source code for 3D racing game', 'In progress', '01/05/2015', '03/05/2015')

insert into PROJECT (Manager, PDescription, PStatus, StartDate, EndDate)
values (2, 'Test videogame for bugs', 'Not started', '03/05/2015', '05/05/2015')

These two are the ones assigned to the employee above, notice Manager for both is 2, and the EmployeeID of Chuck is supposed to be 2. So, I'm supposed to display the employee name as a full name, combining the first and last name, of those who have been assigned two or more projects (in this case, Chuck). 这两个是上面分配给员工的那个,Notice Manager的两个都是2,而Chuck的EmployeeID应该是2。所以,我应该将员工姓名显示为全名,将名字和姓氏结合在一起已分配两个或多个项目(在本例中为Chuck)的人员的姓名。

I wrote this code: 我写了这段代码:

select 
    FirstName + LastName as FullName 
from 
    EMPLOYEE
where 
    EmployeeID = PROJECT.Manager and count(PROJECT.Manager) >= 2

But instantly I get this error: 但是我立即收到此错误:

The multi-part identifier "PROJECT.Manager" could not be bound. 不能绑定多部分标识符“ PROJECT.Manager”。

Am I supposed to make an inner join to recognize the PROJECT table? 我是否应该进行内部联接以识别PROJECT表? But I'm only supposed to display the name of the employee. 但是我只应该显示雇员的姓名。 How can I manage to use the PROJECT.manager column values without displaying them? 如何在不显示它们的情况下设法使用PROJECT.manager列值?

Thank you very much in advance. 提前非常感谢您。

You have to Join Project table, Add Group by with having clause to filter the Manager 您必须加入Project表, Group by具有having子句的“添加Group by来过滤Manager

select FirstName +' '+ LastName as FullName 
from EMPLOYEE
INNER JOIN PROJECT
on EmployeeID = PROJECT.Manager
group by FirstName +' '+ LastName
Having count(PROJECT.Manager) >= 2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM