我正在用另一个字段datetime(datatype)更新一个字段,所以在更新时应该少一分钟,所以我正在使用DATE_SUB()。但是我在SyntaxError: missing ) after argument list附近收到错误INTERVAL

码:

for(var k=0;k<grouppedArray[i][j].length;k++){
    if(grouppedArray[i][j][k+1]){
        db.query('update userRegister set  logout= ? where userId = ? and catId = ?', [SUBDATE(grouppedArray[i][j][k+1].login, INTERVAL 1 MINUTE), 1, grouppedArray[i][j][k].userId, grouppedArray[i][j][k].catId], function (err, updatedLogout) {

        }
    }
}


我在哪里错了?请帮忙

最佳答案

尝试以下方法:

for(var k=0;k<grouppedArray[i][j].length;k++){
    if(grouppedArray[i][j][k+1]){
        db.query('update userRegister set  logout= SUBDATE(?, INTERVAL 1 MINUTE) where userId = ? and catId = ?', [grouppedArray[i][j][k+1].login, grouppedArray[i][j][k].userId, grouppedArray[i][j][k].catId], function (err, updatedLogout) {

        }
    }
}


要么

for(var k=0;k<grouppedArray[i][j].length;k++){
    if(grouppedArray[i][j][k+1]){
        db.query('update userRegister set  logout= ? - INTERVAL 1 MINUTE where userId = ? and catId = ?', [grouppedArray[i][j][k+1].login, grouppedArray[i][j][k].userId, grouppedArray[i][j][k].catId], function (err, updatedLogout) {

        }
    }
}

10-07 18:02