我知道有很多人发布了这个,但他们似乎没有像我一样的错误。
当我运行此声明时,我得到了ERROR 1052。
mysql> SELECT module_staff.StaffName AS Staff,
SUM(modules.HoursPerWeek) AS Total_Worked
FROM module_staff, modules
WHERE ModuleCode IN (SELECT ModuleCode
FROM module_staff
WHERE StaffName ='Nigel Cosworth');
但是下面这段代码确实有效。
mysql> SELECT Title,
SUM(modules.HoursPerWeek) AS Total_Worked
FROM modules
WHERE ModuleCode IN(SELECT ModuleCode
FROM module_staff
WHERE StaffName ='Nigel Cosworth');
module_staff具有ModuleCode和StaffName
列和仅需要模块的列是HoursPerWeek,Title和ModuleCode
答案 0 :(得分:0)
我认为错误在于JOIN
。
尝试更新您的查询,如下所示:
SELECT ms.StaffName AS Staff, SUM(m.HoursPerWeek) AS Total_Worked
FROM module_staff ms
LEFT JOIN modules m
ON ms.ModuleCode = m.ModuleCode
WHERE ms.StaffName ='Nigel Cosworth';
答案 1 :(得分:0)
SELECT ms.StaffName AS Staff, SUM(m.HoursPerWeek) AS Total_Worked
FROM module_staff ms
LEFT JOIN modules m
ON ms.ModuleCode = m.ModuleCode
WHERE ms.StaffName ='Nigel Cosworth';
适合你......