MYSQL触发器 - 使用SUM和JOIN

时间:2016-10-15 18:18:16

标签: mysql join group-by sum

我有两张桌子:
weekweekTeam_Number的{​​{1}}表 列PointsTeams的{​​{1}}表 我希望Team_NumberSession1Points列中sum列的所有Points {1}},然后将其添加到week week列中的表格。

我试过了:

Teams

没有用。我更新Session1Points表后,我希望触发它。我需要先UPDATE Teams P SET Session1Points = (SELECT SUM(Points) from week where week.Team_Number= P.Team_Number) where P.Team_Number = New.Team_Number 吗?

1 个答案:

答案 0 :(得分:1)

你可以这样使用JOIN

function readHtml(callback) { // pass in a callback to call once all rows are read and all html is accumulated
  var html = '';
  db.serialize(function() {
    // read all the rows and accumulate html as before
    db.each("SELECT rowid AS id, info FROM logger", function(err, row) {
      html = html + '<tr><td>' + row.info + '<td><tr>';
    }, function() { 
      callback(html); // use the second callback to signal you are done and pass the html back
    });
  });
}
相关问题