从联接表中选择计数

时间:2020-10-26 22:36:10

标签: javascript node.js

我正在尝试选择每个帖子的顶数。在我的代码中,表是T3。我似乎无法获得理想的结果,我不确定为什么。请帮忙。

function timeLineSql(Id, ifRoute) {
  var preparedStatement, query;
  ifRoute == "post" ? 
  (preparedStatement = [Id, lastIdOfPosts],  query = "SELECT T1.postTitle, T1.youtubeUrl, T1.posterId, T1.textarea, T1.category, T1.postTime, T1.id, T2.name, T2.title, T2.pathToProfilePicture, COUNT(T3.likerId) FROM posts AS T1 " +
  "JOIN likes AS T3 ON T3.idOfPost = T1.id " +
  "JOIN singleHorizontal AS T2 ON T1.posterId = T2.id AND T1.posterId = ? AND T1.id > ? ORDER BY T1.id LIMIT 1")
  : (preparedStatement = [Id],  query = "SELECT T1.postTitle, T1.youtubeUrl, T1.posterId, T1.textarea, T1.category, T1.postTime, T1.id, T2.name, T2.title, T2.pathToProfilePicture FROM posts AS T1 " + 
  "JOIN singleHorizontal AS T2 ON T1.posterId = T2.id AND T1.posterId = ? ORDER BY T1.id LIMIT 1");
  return { ps: preparedStatement, q: query };
}

0 个答案:

没有答案