如何在相同的查询中使用AND和OR运算符进行后续处理?

我执行下面的查询,但我给错误。 我想结束我发布的SQL查询的结果。

userServiceAppointmentModel.findAll({ where: { technician_id: resultsFromAuthentication.technician_id, is_confirmed_by_user: 1, $or: { service_start_time: { gte: curLocalDate }, service_running_status: 1 } }, attributes: attributes }).complete(function (err, appointmentResponse) { if (err) { console.log(err); } SELECT `id`, `technician_id`, `user_id`, `service_id`, `service_name`, `service_location_string`, `service_location_latitude`, `service_location_longitude`, `service_start_time`, `service_end_time`, `notes`, `total_cost`, `service_cost`, `is_confirmed_by_user`, `is_confirmed_by_technician`, `service_running_status`, `service_start_time_by_technician`,`service_complete_time_by_technician` FROM `user_service_appointment` AS `user_service_appointment` WHERE `user_service_appointment`.`technician_id`=154 AND `user_service_appointment`.`is_confirmed_by_user`=1 AND (`user_service_appointment`.`service_start_time` >='2015-02-26 01:07' OR `user_service_appointment`.`service_running_status`=1) 

Solutions Collecting From Web of "如何在相同的查询中使用AND和OR运算符进行后续处理?"

至less在2.0.0版本中,您可以使用Seuqlize.and和Sequelize.or

为你的情况

 .. where: {where: Sequelize.and( {technician_id: resultsFromAuthentication.technician_id}, {is_confirmed_by_user: 1}, Sequelize.or({ service_start_time: { gte: curLocalDate }}, {service_running_status: 1} ) ) .. 
  userServiceAppointmentModel.findAll({where: Sequelize.and( {technician_id: resultsFromAuthentication.technician_id}, {is_confirmed_by_user: 1}, Sequelize.or({ service_start_time: { gte: curLocalDate }}, {service_running_status: 1} ) ) 

})。complete(function(err,appointmentResponse){

在新版本中尝试像这样

  model.update( req.body, { where: { task_id: req.params.task_id, $and: {id: 11} $gt: {end_date: myDate} } } ) .then(function () { res.status(200).json({"message":"done"}) } ) .catch(function (err) { }) 

有关更多信息,请参阅文档

这里我想提一些他们

 $and: {a: 5} // AND (a = 5) $or: [{a: 5}, {a: 6}] // (a = 5 OR a = 6) $gt: 6, // > 6 $gte: 6, // >= 6 $lt: 10, // < 10 $lte: 10, // <= 10 $ne: 20, // != 20 $eq: 3, // = 3 $not: true, // IS NOT TRUE $between: [6, 10], // BETWEEN 6 AND 10 $notBetween: [11, 15], // NOT BETWEEN 11 AND 15 $in: [1, 2], // IN [1, 2] $notIn: [1, 2], // NOT IN [1, 2] $like: '%hat', // LIKE '%hat' $notLike: '%hat' // NOT LIKE '%hat' $iLike: '%hat' // ILIKE '%hat' (case insensitive) (PG only) $notILike: '%hat' // NOT ILIKE '%hat' (PG only) $like: { $any: ['cat', 'hat']} // LIKE ANY ARRAY['cat', 'hat'] - also works for iLike and notLike $overlap: [1, 2] // && [1, 2] (PG array overlap operator) $contains: [1, 2] // @> [1, 2] (PG array contains operator) $contained: [1, 2] // <@ [1, 2] (PG array contained by operator) $any: [2,3] // ANY ARRAY[2, 3]::INTEGER (PG only)