我是一名新手,正在学习使用Node Js
。在我的Node Js
项目中,我正在使用sequelize ORM
来连接MySql
数据库。
这是我想要编写的按月查询语句:
SELECT * FROM cubbersclosure WHERE MONTH(fromDate) = '04'
这里的fromDate
字段类型为date
。
以下是我的代码:
var fromDate = '2019-04-01'
var fromDateMonth = new Date(fromDate);
var fromMonth = (fromDateMonth.getMonth()+ 1) < 10 ? '0' + (fromDateMonth.getMonth()+1) : (fromDateMonth.getMonth()+1);
CubbersClosure.findAll({
where:{
// select query with Month (04)... //fromMonth
}
}).then(closureData=>{
res.send(closureData);
}).catch(error=>{
res.status(403).send({status: 'error', resCode:200, msg:'Internal Server Error...!', data:error});
});
这里的
fromMonth
只获取日期中的月份,所以我想编写选择特定月份数据的代码查询语句。
D:\my_project\choose_cubby\internal-test\app\controller\cubber\cubbers.controller.js:907 sequelize.where()
。 - Ramesh Swhere: { $and: sequelize.where(sequelize.fn("monthc", sequelize.col("fromDate")), fromMonth) }
,但仍然显示错误。 - Ramesh SFUNCTION choose_cubby.monthc 不存在
。 - Ramesh S