如何在MySQL中修复错误代码1241

时间:2016-02-07 05:54:16

标签: mysql

SELECT c.Staff_no, c.Start_datetime, c.End_datetime, s.First_name, s.Profession, s.Department, s.Gender
 FROM duty_roster_1501003f c, staff_1501003f s where c.Staff_no = s.Staff_no IN
 (SELECT Staff_no, Start_datetime, End_datetime FROM duty_roster_1501003f WHERE Remarks = 'overtime' ORDER BY staff_no);

错误代码表示操作数应包含1列。我该怎么做才能解决它?

2 个答案:

答案 0 :(得分:1)

您在IN

之前缺少AND / OR和字段名称

WHERE c.Staff_no = s.Staff_no AND someField IN(子查询)

此外,子查询应该只返回一个字段,而不是现在返回的字段。

答案 1 :(得分:1)

你说的地方:

...  WHERE c.Staff_no = s.Staff_no IN (SELECT Staff_no, Start_datetime, End_datetime FROM duty_roster_1501003f WHERE Remarks = 'overtime' ORDER BY staff_no);

这是无效的。也许你想要:

...  WHERE c.Staff_no = s.Staff_no AND c.Staff_no IN
      (SELECT Staff_no FROM duty_roster_1501003f WHERE Remarks = 'overtime')

IN的选择只能返回1列(你会用其他列做什么?)