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. 怎么学好php2. Thinkphp 下载地址找不到了?3. python - import里的dot是以哪个路径作为根目录的?4. javascript - 百度地图自己的产品可以精确定位,为什么我调用他的公开API却必须经过用户同意才能获取精确定位,而且还慢?5. mybatis - Java关于Mysql的随机id生成6. 网页爬虫 - Python爬虫入门知识7. mysql - 数据库建字段,默认值空和empty string有什么区别 1108. 在MySQL数据库中查询表里的记录条数的代码怎么写?9. 如何更新/删除指定的两条或多条数据10. javascript - echart+百度地图