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. python 计算两个时间相差的分钟数,超过一天时计算不对2. java - web端百度网盘的一个操作为什么要分两次请求服务器, 有什么好处吗3. docker 17.03 怎么配置 registry mirror ?4. 手机开发 - Android蓝牙模块连接后怎么接收数据?求助5. docker容器呢SSH为什么连不通呢?6. 正在使用electron和node.js做桌面应用,需要实时监听是否有网络连接,node或者electron是否可以做到7. dockerfile - [docker build image失败- npm install]8. macos - mac下docker如何设置代理9. node.js - express框架,设置浏览器从缓存中读取静态文件,只有js从缓存中读取了,css还有一些图片为何没有从缓存中读取?10. python - flask post提交timestamp不能作为参数,这是为什么?

网公网安备