2017-09-19 12 views
0

このクエリはsequelizeを使用して実行する必要があります。NodeJSを使用して複数の場所にサブクエリを書き込む方法

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'} 
      } 
     } 
    }) 

答えて

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"}); 
      }); 
+0

私は生のクエリを使用するために知っているが、私は上記の形式でミスをしたものを明確にする必要があります。 –

+0

エラーを貼り付けることはできますか? –

関連する問題