Mysql报错Operand should contain 1 column(s)
·
Mysql报错Operand should contain 1 column(s)
1.报错
ERROR 1241 (21000): Operand should contain 1 column(s)
2. 报错原因
- 这个语句的出现多是因为将select 的结果集用()包住了。
- 使用
()
将select
括注是正常的,但是可能是字段使用不当,如下面的SQL:
select
pit_key
,employee_code
,department_id
,value_date
from pit_employee_department ped
where ped.employee_code = 'GSCQ3349'
and ped.value_date < date_format(date_sub(curdate(), interval day(curdate()) - 1 day),'%Y%m%d')
and ped.pit_key not in
( select
pit_key
,value_date
from pit_employee_department ped_1
inner join
(
select
max(value_date) as max_date
from pit_employee_department ped
where ped.value_date <= date_format(date_sub( date_sub(curdate(), interval day(curdate()) - 1 day),interval 1 month),'%Y%m%d')
and employee_code = 'GSSH0039'
)ped_2
on ped_1.value_date < ped_2.max_date
and ped_1.employee_code = 'GSSH0039'
);
执行上面的SQL 报这个错的原因是:在子查询中使用了pit_key
和 value_date
两个字段,而比较的选项是pit_key not in (...)
,字段不一致导致出错。
3. 解决方案
针对不同的原因进行修改。
更多推荐
所有评论(0)