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-compose中volumes的問題2. mysql 一個sql 返回多個總數3. CSS3 畫如下圖形4. 在mac下出現了兩個docker環境5. 如何用筆記本上的apache做微信開發的服務器6. android - rxjava merge 返回Object對象數據如何緩存7. javascript - 螞蟻金服里的react Modal方法,是怎么把元素插入到頁面最后的8. python - Scrapy存在內存泄漏的問題。9. docker 下面創建的IMAGE 他們的 ID 一樣?這個是怎么回事????10. angular.js - ionic2 瀏覽器跨域問題
