mysql - sql subquery return more than 1 row
問(wèn)題描述
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
我的疑問(wèn)是,為何代碼1會(huì)出現(xiàn)Error Code: 1242. Subquery returns more than 1 row這種錯(cuò)誤,而代碼2不會(huì)? 謝謝各位大神
背景:我是在存儲(chǔ)過(guò)程中使用的...
問(wèn)題解答
回答1:where xxx = yyy的時(shí)候,右邊必須是單一的值,不能是多個(gè)值,而你第一個(gè)語(yǔ)句里面的
(SELECT oid FROM orders_father where TIMESTAMPDIFF(HOUR,odlvtime,now())>parameter and ostatus=4)as tempTable)
會(huì)查出多個(gè)值,所以報(bào)Error Code: 1242. Subquery returns more than 1 row的錯(cuò)誤
解決的方法就是把where xxx = yyy變成where xxx in(yyy)或者where xxx = any yyy,這兩個(gè)表達(dá)是一個(gè)意思,不過(guò)any還可以其他的比較,比如where xxx > any yyy
回答2:any 相當(dāng) in()
相關(guān)文章:
1. javascript - 百度echarts圖表如何修改2. 微信無(wú)法掃描phpqrcode生成的二維碼3. index.php錯(cuò)誤,求指點(diǎn)4. PHPExcel表格導(dǎo)入數(shù)據(jù)庫(kù)怎么導(dǎo)入5. vue.js - Environment variable $ANDROID_HOME not found !(macOS)6. 什么是前后端分離?用vue angular等js框架就能實(shí)現(xiàn)前后分離了嗎?7. android - 試用百度地圖sdk,運(yùn)行結(jié)果出來(lái)一片空白8. 用PHP怎么在微信公眾號(hào)里使用模板信息,公眾號(hào)還未做開(kāi)發(fā)?9. html5 - 如何解決微信網(wǎng)頁(yè)偶爾出現(xiàn)的亂碼問(wèn)題?10. node.js - vue-cll+sass 樣式不出來(lái) 已經(jīng)npm install sass、 sass-loader了
