桌上联赛
team_id name wins losses played recorded created
1 dodgers 10 4 14 1364790000 1353215830
2 angels 9 6 15 1364790000 1353661376
3 pirates 12 3 15 1364790000 1353543466
team_id name wins losses played recorded created
1 dodgers 22 9 31 1367274480 1353215830
2 angels 14 17 31 1367274480 1353661376
3 pirates 19 13 32 1367274480 1353543466
4 yankees 10 9 19 1367274480 1365577298
5 brewers 7 11 18 1367274480 1365394448
希望结果为:
team_id name wins losses played
1 dodgers 12 5 17
2 angels 5 11 16
3 pirates 7 10 17
4 yankees 10 9 19
5 brewers 7 11 18
我已经尝试了几个使用连接的查询,但都没有成功。每天,球队的胜利、失败和比赛都会被记录下来,并在记录栏上加盖时间戳。团队是在 created 列上创建的。(所有unix时间戳)我正在尝试的两个日期之间有几行,但我不需要它们来进行此查询。
我想做的是为现有和新团队获得四月的赢/输/出场,我尝试了几个查询,这里有几个没有给我想要的结果:
SELECT a.name as name, a.wins-b.wins as wins, a.losses-b.losses as losses, a.played-b.played as played from league a join league b on a.id=b.id where a.recorded= 1367274480 and b.recorded= 1364790000
和
SELECT new.*, new.wins-old.wins as newwins, new.losses-old.losses as newlosses FROM league new LEFT JOIN league old ON new.id=old.id WHERE (new.recorded=1367274480 and old.recorded=1364790000) or (new.created > 1364790000 and new.recorded=1367274480) GROUP BY new.id