这是我正在使用的查询:
SELECT q.questions
,a2.answers answer
,a.tally tally
FROM (
SELECT idquestions
,MAX(tally) tally
FROM answers
GROUP BY idquestions
) a
LEFT JOIN (
SELECT idanswers
,idquestions
,answers
,tally
FROM answers
) a2 ON a2.idquestions = a.idquestions
AND a2.tally = a.tally
LEFT JOIN questions q ON q.idquestions = a.idquestions
在Workbench中调用时,它完全按预期执行,但是当从我的节点服务器调用时,我得到一个空响应。
(编辑)这是整个节点路线:
var data = "";
connection.query("SELECT q.questions, a2.answers answer, a.tally tally FROM (SELECT idquestions, MAX(tally) tally FROM answers GROUP BY idquestions) a LEFT JOIN (SELECT idanswers, idquestions, answers, tally FROM answers) a2 ON a2.idquestions = a.idquestions AND a2.tally = a.tally LEFT JOIN questions q ON q.idquestions = a.idquestions",
function(err, rows, fields){
if(rows.length != 0){
data = rows;
res.json(data);
}else{
data = 'No data Found..';
res.json(data);
}
res.end();
});
});