錯誤:“無法識別的名稱: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