如何以续集的方式编写此查询:
select COUNT(*)
from r5.users
WHERE
DATE_FORMAT(createdAt,'%Y%c%d')=DATE_FORMAT(current_date(),'%Y%c%d')
答案 0 :(得分:0)
你可以这样做,
Model.users.count({
where: Model.Sequelize.where(
Model.Sequelize.fn('DATE_FORMAT',Model.Sequelize.col('createdAt'),"%Y%c%d"),
{like:Model.Sequelize.fn('DATE_FORMAT',Model.Sequelize.fn('current_date'),"%Y%c%d")})
});
Sequelize.fn
可用于调用数据库函数,它需要Sequelize.fn(functionToCall, argumentsToPassToIt)
Sequelize.Col
用于引用特定列,例如createdAt
Sequelize.where可用于向要添加的列添加函数