我正在编写需要多个“或”语句的查询。
这是我在哪里
{
date_added: {
'$lte': '2019-04-18', '$gte': '2019-04-11'
},
'$or': [
{ id: [Array], secondary_id:[Array] }
],
'$and': [
{ third_id: [Array], fourth_id:[Array] }
],///make it into $or
}
使得语句从哪里更改
WHERE ("date_added" <= '2019-04-18' AND "date_added" >= '2019-04-11')
AND ("id" IN ('10') or "secondary_id" in ('11'))
AND ("third_id" IN ('12') and "fourth_id" in ('13'))
INTO
WHERE ("date_added" <= '2019-04-18' AND "date_added" >= '2019-04-11')
AND ("id" IN ('10') or "secondary_id" in ('11'))
AND ("third_id" IN ('12') OR "fourth_id" in ('13'))
另一种说法是,我该如何使用续集来进行(A或B)和(C或D)
答案 0 :(得分:0)
您应该使用Sequelize operator symbols而不是示例中的字符串值,因为它们已被弃用。要在您的SQL中重新创建查询,您需要执行以下操作:
const Op = Sequelize.Op
where: {
date_added: {
[Op.between]: ['2019-04-18', '2019-04-11'],
},
id: {
[Op.in]: arrayOfIds,
}
[Op.or]: [
{
channel_type: {
[Op.like]: {
[Op.any]: ['facebook', 'instagram'],
},
},
},
],
}
SQL
WHERE date_added BETWEEN '2019-04-18' AND '2019-04-11'
AND id IN (... your id array)
AND (
channel_type LIKE 'facebook'
OR channel_type LIKE 'instagram'
)