MySQL查询在Workbench中工作但不在服务器上工作

时间:2016-04-11 19:24:34

标签: mysql sql node.js

这是我正在使用的查询:

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();
});

});

0 个答案:

没有答案