错误代码:1054。未知列

时间:2011-09-07 11:35:28

标签: sql mysql-error-1054

我有以下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'; 

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

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

为什么我收到此错误?

Project_task_id属于努力表

Image of my efforts table

更新:

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

2 个答案:

答案 0 :(得分:8)

你的语法错了,它应该是:

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';  

答案 1 :(得分:1)

请注意,据我所知,MySQL对表名称(而不是列名称)区分大小写......这可能会导致查询出现问题......?随着StevieG的纠正