这是sql:
SELECT IFNULL(A.price, B.price)
FROM table1 B
INNER JOIN (
SELECT price
,product_id
FROM table2
WHERE user_id = xxx
) A
ON A.product_id = B.product_id
如何使用sequelize.findAll()
获得相同的结果答案 0 :(得分:0)
假设你有从A到B定义的关联
Model.A.findAll({where:{user_id:XXX}, include:Model.B})
如果您没有关联,可以使用raw queries。
sequelize.query('SELECT IFNULL(A.price, B.price) FROM table1 B INNER JOIN (SELECT price, product_id FROM table2 WHERE user_id=:uid) A ON A.product_id=B.product_id',{replacements:{uid:xxx}})