我正在尝试使用node js
在sequelize
中进行costum查询。
所以我有api电话:
router.route('/api/divisionData/:division_id')
.get(function (req, res) {
var division = Division.build();
division.retrieveDataById(req.params.division_id, function (users) {
if (users) {
res.json(users);
} else {
res.status(401).send("Data not found");
}
}, function (error) {
res.send("Data not found");
});
});
然后我有了retrieveDataById:
sequelize.query("select division_id, (modules.user_id) as modules_taken, ROUND(avg(scores.score),2) as average_score from " +
"user join " +
"(select user_id, score from test_score " +
"UNION ALL " +
"select user_id, score from task_score WHERE status_id = 1 " +
") as scores " +
" on user.id = scores.user_id " +
" join ( " +
" SELECT user_id FROM test_score " +
" UNION all " +
" SELECT user_id FROM task_score WHERE status_id NOT IN (3) " +
" UNION all " +
" SELECT user_id FROM elearning_score " +
" union all" +
" SELECT user_id FROM academy_screening " +
" union all" +
" SELECT user_id FROM academy_evaluation " +
" union all " +
" select user_id FROM academy_survey " +
" union al " +
" select user_id FROM offline_score " +
" ) as modules on user.id = modules.user_id WHERE division_id = " + user_id +" group by division_id", {type: sequelize.QueryTypes.SELECT})
.then(onSuccess).error(onError)
我已在MySql中测试了查询,但它运行正常,但此调用的返回是:
data not found
谁能告诉我这里我做错了什么?