我是sequelize的新手,如何将mysql查询转换为sequelize

时间:2018-11-03 10:31:41

标签: mysql node.js

MySQL查询:

SELECT categories.name AS CATEGORIES,GROUP_CONCAT(subcategories.name) AS 
SUBCATEGORIES FROM subcategories INNER JOIN categories ON 
subcategories.categorieName = categories.name GROUP BY categories.name;

1 个答案:

答案 0 :(得分:0)

对于已经准备好的SQL查询,您可以使用函数sequelize.query

您可以尝试:

sequelize.query("SELECT categories.name AS CATEGORIES,GROUP_CONCAT(subcategories.name) AS SUBCATEGORIES FROM subcategories INNER JOIN categories ON subcategories.categorieName = categories.name GROUP BY categories.name")
.spread((results, metadata) => {
  // Results will be an empty array
  // and metadata will contain the number of affected rows.
})

您的参考,以获取更多详细信息:

http://docs.sequelizejs.com/manual/tutorial/raw-queries.html

我希望对您有帮助