SQL 错误代码:1054。未知列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7333176/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 12:01:21  来源:igfitidea点击:

Error Code: 1054. Unknown column

sqlmysql-error-1054

提问by David

I have the following SQL statement:

我有以下 SQL 语句:

SELECT efforts.user_id, project_tasks.task_name, sum(hours) 
FROM efforts, users, project_tasks
INNER JOIN PROJECT_TASKS pu ON efforts.project_task_id = pu.id  
INNER JOIN USERS u ON efforts.users_id = u.id
WHERE project_tasks.project_id = '2'; 

And when I run it I get the following error:

当我运行它时,我收到以下错误:

Error Code: 1054. Unknown column 'efforts.project_task_id' in 'on clause'

Why am I getting this error?

为什么我收到这个错误?

Project_task_id belongs to efforts table

project_task_id 属于努力表

Image of my efforts table

我的努力表的图片

Updated:

更新:

SELECT u.full_name, pu.task_name, hours 
FROM efforts
INNER JOIN project_tasks pu ON efforts.project_task_id = pu.id   
INNER JOIN users u ON efforts.user_id = u.id 
GROUP BY user_id, task_name

回答by StevieG

Your syntax is wrong, it should be:

你的语法错误,应该是:

SELECT efforts.user_id, pu.task_name, sum(hours)  
FROM efforts
INNER JOIN PROJECT_TASKS pu ON efforts.project_task_id = pu.id   
INNER JOIN USERS u ON efforts.user_id = u.id 
WHERE pu.project_id = '2';  

回答by Lukas Eder

Note that as far as I know, MySQL is case-sensitive on table names (not on column names)... That might cause some trouble in your query...? Along with StevieG's correction

请注意,据我所知,MySQL 对表名(而不是列名)区分大小写...这可能会在您的查询中造成一些麻烦...?随着 StevieG 的更正