1

我需要使用 sequelize 来执行这个查询。

select * from mysqlDB.songTable where
X in (SELECT X FROM movieDB4.songTable where Y like('%pencil%') and Z='title') and
Y='tam' and Z='language';

我试过这样。但它会引发一些无效的值 [对象] 错误。请帮助解决此查询。

const tempSQL = sequelize.dialect.QueryGenerator.selectQuery('songTable',{
      attributes: ['X'],
      where: {
           Y: {$like: '%'+text[i]},
           Z: "content_title"
      }})
      .slice(0,-1); // to remove the ';' from the end of the SQL

  User.findAll({
      where: {
          X: {
               $in: sequelize.literal('(' + tempSQL + ')'),
               $and: {Y: lang.substring(0,3),
                      Z: 'language'}
          }
      } 
  })
4

1 回答 1

0

您可以使用 sequelize.query() 来执行原始查询。

例子

return this.sequelize.query(`SELECT category_id, category_name from table_categories where category_id in (SELECT DISTINCT category_id from table_authorized_service_center_details where center_id in (SELECT center_id from table_authorized_service_center where brand_id ${condition}));`).then((results) => {
                if (results.length === 0) {
                    reply({status: true, categories: [], forceUpdate: request.pre.forceUpdate});
                } else {
                    reply({status: true, categories: results[0], forceUpdate: request.pre.forceUpdate});
                }
            }).catch((err) => {
                console.log(err);
                reply({status: false, message: "ISE"});
            });
于 2017-09-19T12:19:33.237 回答