error - The multi-part identifier "Grant.EmpID" could not be bound.
错误-多部分标识符“授予”。“不能被束缚”。
query -
查询-
select emp.EmpID,
COUNT(*) as CountRecords,
COUNT(GrantName) AS CountValues
From Employee as emp full join [Grant] as gr
on emp.EmpID = [Grant].EmpID
-- This is the cause for the error ! Change it to gr.EmpID
group by emp.EmpID
Why does this error occur ? Can't I call a person by real name and also by nickname ?
为什么会发生这种错误?我不能用真名和绰号叫人吗?
2 个解决方案
#1
5
You're aliasing [Grant]
. In other words, you're stating that from here on out, [Grant]
will be referred to as gr
.
你混叠(拨款)。换句话说,您正在声明,从现在开始,[Grant]将被称为gr。
Use the ALIAS
in the GROUP BY
clause, not the tableName.
使用GROUP BY子句中的别名,而不是tableName。
SELECT emp.EmpID,
COUNT(*) as CountRecords,
COUNT(GrantName) AS CountValues
FROM Employee as emp
FULL JOIN [Grant] as gr
on emp.EmpID = gr.EmpID -- use the alias.
GROUP BY gr.EmpID -- use the alias.
here's the SQL Order of Operation
这是操作的SQL命令。
- FROM clause
- 从条款
- WHERE clause
- WHERE子句
- GROUP BY clause
- GROUP BY子句
- HAVING clause
- 有条款
- SELECT clause
- SELECT子句
- ORDER BY clause
- ORDER BY子句
#2
0
No you can't because sql server is not a human. imagine we have an Employee table which references itself
不行,因为sql server不是人。假设我们有一个引用自己的Employee表
select *
from Employee Emp, Employee Mng
where Emp.ManagerID = Mng.EmployeeID
Mng and Emp are two instances of Employee
Mng和Emp是Employee的两个实例。
so if I select
如果我选择
select * from Employee e, Employee
it will return all employee TWO times, because I am telling give me employees once under the name Employee
once under the name e
(alias)
它将会返回所有员工2次,因为我告诉给我员工曾经在名字下面的雇员名字e(别名)
#1
5
You're aliasing [Grant]
. In other words, you're stating that from here on out, [Grant]
will be referred to as gr
.
你混叠(拨款)。换句话说,您正在声明,从现在开始,[Grant]将被称为gr。
Use the ALIAS
in the GROUP BY
clause, not the tableName.
使用GROUP BY子句中的别名,而不是tableName。
SELECT emp.EmpID,
COUNT(*) as CountRecords,
COUNT(GrantName) AS CountValues
FROM Employee as emp
FULL JOIN [Grant] as gr
on emp.EmpID = gr.EmpID -- use the alias.
GROUP BY gr.EmpID -- use the alias.
here's the SQL Order of Operation
这是操作的SQL命令。
- FROM clause
- 从条款
- WHERE clause
- WHERE子句
- GROUP BY clause
- GROUP BY子句
- HAVING clause
- 有条款
- SELECT clause
- SELECT子句
- ORDER BY clause
- ORDER BY子句
#2
0
No you can't because sql server is not a human. imagine we have an Employee table which references itself
不行,因为sql server不是人。假设我们有一个引用自己的Employee表
select *
from Employee Emp, Employee Mng
where Emp.ManagerID = Mng.EmployeeID
Mng and Emp are two instances of Employee
Mng和Emp是Employee的两个实例。
so if I select
如果我选择
select * from Employee e, Employee
it will return all employee TWO times, because I am telling give me employees once under the name Employee
once under the name e
(alias)
它将会返回所有员工2次,因为我告诉给我员工曾经在名字下面的雇员名字e(别名)