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. 關docker hub上有些鏡像的tag被標記““This image has vulnerabilities””2. docker - 如何修改運行中容器的配置3. docker鏡像push報錯4. 關于docker下的nginx壓力測試5. angular.js - angularjs的自定義過濾器如何給文字加顏色?6. Docker for Mac 創建的dnsmasq容器連不上/不工作的問題7. 前端 - @media query 使用出現的問題?8. html5和Flash對抗是什么情況?9. java - 如何點擊按鈕,重新運行(我是初學者)?10. html - css氣泡,實現“倒三角(不知道算不算三角了)”可透明的。

網公網安備