gpt4 book ai didi

mysql - Node JS mysql用数组数组删除多行

转载 作者:可可西里 更新时间:2023-11-01 07:19:43 26 4
gpt4 key购买 nike

我需要进行一个能够从我的表中删除多行的查询。为了做到这一点,我在数组中创建了一个数组,其中包含需要传递给该查询的值。这是我的代码:

var deleteRooms = [ [ 3, 23 ], [ 4, 23 ], [ 5, 23 ], [ 2, 23 ]];

connection.query("DELETE FROM rate_plans_rooms WHERE room_id = ? AND rate_plan_id = ? ",
[deleteRooms],function(err,results){
if(err){return console.log(err)}

else
{
console.log('sended');
}

});

但是每次我收到这样的错误:

{ Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check
the manual that corresponds to your MariaDB server version for the
right syntax to use near ' (4, 23), (5, 23), (2, 23) AND rate_plan_id
= ?' at line 1

如何解决这个问题并正确发送我的查询?

最佳答案

您的问题的解决方案是在查询中使用“IN”:

var deleteRooms = [[3,23],[4,23],[5,23], [2,23]];

connection.query("DELETE FROM rate_plans_rooms WHERE (room_id, rate_plan_id) IN (?)",
[deleteRooms],function(err,results){

if(err) return console.log(err)
else console.log('sended');
});

关于mysql - Node JS mysql用数组数组删除多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44610613/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com