我有这些表:
具有这种结构
[
"products" :
{
"id": 1,
"orginalName": "146153-0100 ",
"title": null,
"stores": [
{
"id": 1,
"stock": 100,
"minOQ": 1,
"maxOQ": 0
},
{
"id": 2,
"stock": 100,
"minOQ": 1,
"maxOQ": 0,
}
],
"productproperties": [
{
"id": 1,
"productId": 1,
"propertyId": 8,
"propertyOptionId": 5
},
{
"id": 2,
"productId": 1,
"propertyId": 9,
"propertyOptionId": 11
},
{
"id": 3,
"productId": 1,
"propertyId": 10,
"propertyOptionId": 9
}
]
}
]
我想按选定的选项过滤产品,假设选定的选项是11和9
如何使用findAll,where和...在Sequelize 5.6中实现以下sql查询:
select * from products as p
inner join stores as sr on sr.productId = p.id
where (select count(*) from productProperties where propertyOptionId in (11,9) and productId = p.id) >= 2
答案 0 :(得分:0)
我发现在续集中使用查询生成器确实令人困惑, 因此,如果您擅长使用原始sql,则可以按以下方式运行它们
如果学生是您的榜样 然后 const students = Student.query('从学生中选择*);