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. Browser-sync安装失败问题2. javascript - 用jq ajax可以获取不同域的数据吗?3. sublime-text - sublime text 3中编译python(sublimeREPL),如何仅运行单行/选定部分4. python 函数名之后 有一个箭头 这是什么作用?5. javascript - vue中input的blur影响了下拉的点击事件如何解决6. navicat - Mysql无法连接7. html - 关于css选择器的问题8. python中merge后文件莫名变得非常大9. html5 - bootstrap修改样式的问题10. python3.5 urllib.parse.unquote 乱码

网公网安备