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. 主从备份 - 跪求mysql 高可用主从方案2. python - django 里自定义的 login 方法,如何使用 login_required()3. python如何不改动文件的情况下修改文件的 修改日期4. mysql主从 - 请教下mysql 主动-被动模式的双主配置 和 主从配置在应用上有什么区别?5. angular.js - 不适用其他构建工具,怎么搭建angular1项目6. android-studio - Android 动态壁纸LayoutParams问题7. mysql优化 - mysql count(id)查询速度如何优化?8. javascript - git clone 下来的项目 想在本地运行 npm run install 报错9. sql语句如何按or排序取出记录10. node.js - 使用 superagent 抓取 UTF-8网站乱码
