検索

ホームページ  >  に質問  >  本文

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不会? 谢谢各位大神

背景:我是在存储过程中使用的...

伊谢尔伦伊谢尔伦2873日前691

全員に返信(2)返信します

  • 黄舟

    黄舟2017-04-17 15:31:52

    where xxx = yyy、右側は複数の値ではなく単一の値である必要があり、最初のステートメントでは

    リーリー

    は複数の値を検出するため、エラー Error Code: 1242. Subquery returns more than 1 row が報告されます

    の解決策は、where xxx = yyywhere xxx in(yyy) または where xxx = any yyy に変更することです。これら 2 つの式は同じ意味を持ちますが、where xxx > any yyy

    など、他の方法で比較することもできます。

    返事
    0
  • ringa_lee

    ringa_lee2017-04-17 15:31:52

    どれもかなり入っています()

    返事
    0
  • キャンセル返事