错误:“无法识别的名称:employees at [9:8]”
在使用表别名时,可能会遇到“无法识别的名称:employees at [9:8]”错误。让我们分析其原因并提供正确的解决方案。
错误分析:
在提供的SQL查询中:
SELECT
employees.name AS employee_name,
employees.role AS employee_role,
departments.name AS department_name
FROM
`strange-calling-318804.employee_data.Employees`
JOIN
`strange-calling-318804.employee_data.departments`
ON employees.department_id = departments.department_id
在ON
子句中使用了employees
和departments
别名:
ON employees.department_id = departments.department_id
但是,Employees
和departments
表在FROM
子句中没有明确定义别名。这导致了错误,因为BigQuery要求在使用别名之前必须定义它们。
解决方案:
要解决此错误,必须在使用别名之前定义它们:
SELECT
employees.name AS employee_name,
employees.role AS employee_role,
departments.name AS department_name
FROM
`strange-calling-318804.employee_data.Employees` AS employees
JOIN
`strange-calling-318804.employee_data.departments` AS departments
ON employees.department_id = departments.department_id
通过在完整的表引用之后添加别名AS employees
和AS departments
,查询现在可以正确识别表并执行,而不会出现错误。
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3