嗨,我希望你能帮我解决这个问题:
我有这些表格:
Games
id name
1 Game1
2 Game2
3 Game3
Plays
game_id user_id numbers date
1 1 2,12,34,56 2015-06-30 13:15:00
2 1 5,10,22,41 2015-06-30 13:15:00
3 1 1,7,11,34 2015-06-30 13:15:00
1 2 4,17,29,32 2015-06-30 13:15:00
1 1 2,9,19,45 2015-06-31 13:15:00
2 1 5,16,26,31 2015-06-31 13:15:00
3 1 4,12,16,34 2015-06-31 13:15:00
1 1 3,15,27,43 2015-06-01 13:15:00
1 1 1,7,14,29 2015-06-02 13:15:00
2 1 7,23,31,48 2015-06-02 13:15:00
我需要在今天和过去10天之间获得所有user_id = 1次播放但是如果用户没有在一个日期播放,则无论如何都应该返回日期。 结果应该是这样的:
game_id user_id numbers date
1 1 null 2015-06-26 00:00:00
2 1 null 2015-06-26 00:00:00
3 1 null 2015-06-26 00:00:00
same for days 27-28-29
1 1 2,12,34,56 2015-06-30 13:15:00
2 1 5,10,22,41 2015-06-30 13:15:00
3 1 1,7,11,34 2015-06-30 13:15:00
and so on
这是我现在使用的查询,但它只返回实际存在的日期:
SELECT g.id, gam.name, g.played_numbers, g.date FROM plays AS g RIGHT JOIN games AS gam ON g.game_id = gam.id AND g.user_id = 1 AND g.date BETWEEN '2015-05-04 15:00:00' AND '2015-06-03 15:00:00'
提前致谢。