mysql - sql subquery return more than 1 row
问题描述
update orders_father set ostatus=5,ofintimesys=now() where oid =(select oid from(SELECT oid FROM orders_father where TIMESTAMPDIFF(HOUR,odlvtime,now())>parameter and ostatus=4)as tempTable);
这是代码1。
update orders_father set ostatus=5,ofintimesys=now() where oid =any(select oid from(SELECT oid FROM orders_father where TIMESTAMPDIFF(HOUR,odlvtime,now())>parameter and ostatus=4)as tempTable);
这是代码2,在oid=后面增加了any
我的疑问是,为何代码1会出现Error Code: 1242. Subquery returns more than 1 row这种错误,而代码2不会? 谢谢各位大神
背景:我是在存储过程中使用的...
问题解答
回答1:where xxx = yyy的时候,右边必须是单一的值,不能是多个值,而你第一个语句里面的
(SELECT oid FROM orders_father where TIMESTAMPDIFF(HOUR,odlvtime,now())>parameter and ostatus=4)as tempTable)
会查出多个值,所以报Error Code: 1242. Subquery returns more than 1 row的错误
解决的方法就是把where xxx = yyy变成where xxx in(yyy)或者where xxx = any yyy,这两个表达是一个意思,不过any还可以其他的比较,比如where xxx > any yyy
回答2:any 相当 in()
相关文章:
1. 新手入门语法错误:syntax error, unexpected ’:’, expecting ’2. 紧急求助-我们的一位同事突然离职,需要一个后端的同事,项目才能进行,停滞了,那位可以帮帮忙?3. 老师,我的int值为什么不一样4. php链接数据库,mysql_connect 无法使用5. tp6表单令牌6. 请问老师,我导入模板后按视频讲解操作,css跟js还是下载不出来,这个问题能怎么解决?7. 遍历目录下的所有文件8. 我毕业以后在工作之余学了 PHP,都是自学 现在在找这方面的工作 求前辈指导学习方向 工作常用的知识9. index.php错误,求指点10. 提示语法错误语法错误: unexpected ’abstract’ (T_ABSTRACT)

网公网安备