我有以下查询:
select * from winners
join profiles on winners.subscriber_id = profiles.subscriber_id
join comments on comments.profile_id = profiles.vanity
join videos on winners.subscriber_id = videos.subscriber_id
join photos on winners.subscriber_id = photos.subscriber_id
where winners.round_id >= 4 AND winners.active = true
AND (comments.created_at > DATE_SUB( NOW(), INTERVAL 24 HOUR) OR videos.created_at > DATE_SUB( NOW(), INTERVAL 24 HOUR) OR photos.created_at > DATE_SUB( NOW(), INTERVAL 24 HOUR)) AND comments.parent_id = 0;
此查询在cron作业上运行,该作业将为每位获胜者提取过去24小时的最新信息,然后将向每位获奖者粉丝发送最新信息。
我遇到的问题是该查询正在撤回误报,因为如果在过去24小时内发生了对视频的评论,那么它会撤回视频和评论。 无论如何要限制在过去24小时内完成所有事情?
答案 0 :(得分:1)
我会将24小时支票移至加入。这样我们只加入最近更新的项目。
select * from winners
join profiles on winners.subscriber_id = profiles.subscriber_id
left join comments on (comments.profile_id = profiles.vanity AND comments.created_at > DATE_SUB( NOW(), INTERVAL 24 HOUR))
left join videos on (winners.subscriber_id = videos.subscriber_id AND videos.created_at > DATE_SUB( NOW(), INTERVAL 24 HOUR))
left join photos on (winners.subscriber_id = photos.subscriber_id AND photos.created_at > DATE_SUB( NOW(), INTERVAL 24 HOUR))
where winners.round_id >= 4 AND winners.active = true
AND comments.parent_id = 0;