嗨,我在 mysql 中有玩家表。
我需要选择在联赛中 6 个月没有参加过比赛的不活跃球员。
例如->
select * from players where player (matchplayed == true && (in last 6 months condition));
我是mysql的新手
所以会喜欢一些如何处理时间的帮助。
嗨,我在 mysql 中有玩家表。
我需要选择在联赛中 6 个月没有参加过比赛的不活跃球员。
例如->
select * from players where player (matchplayed == true && (in last 6 months condition));
我是mysql的新手
所以会喜欢一些如何处理时间的帮助。
像这样的事情可能会起作用:
SELECT * from players where player_matchplayed == true
&& lastmatch_played_date > DATE_SUB(curdate(),INTERVAL 6 MONTH);
DATE_SUB(curdate(),INTERVAL 6 MONTH)将为您提供从当前日期开始的最后六个月的间隔。您可以使用它来检查lastmatch_playeddate
是否大于它。
希望这可以帮助 。
试试这个查询
SELECT * FROM players
WHERE matchplayed IS NOT NULL
AND last_match < NOW() - INTERVAL 6 MONTH
last_match
是一个 mysql DATE 字段,最后一场比赛信息
matchplayed
是 NULL(未播放)或已播放的另一个值
看看 mysql 日期/时间函数:http ://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html
我认为 DATE_SUB 将完成这项工作或 DATE_DIFF 进行比较。