查询所做的:根据当前时间获取所需的数据,如事件标题、帖子名称、工作日、事件开始时间、事件结束时间。
我将从PHP日期(‘w’)和当前时间传递工作日值。
PROBLEM:我希望它只匹配当前工作日的start_hour (本例中为5)。如果我有AND wp_wcs3_schedule.start_hour > '09:00:00',则需要将此条件限制为适用于当前工作日,在本例中为"5“。
SELECT wp_posts.ID, wp_posts.post_title, wp_posts.post_name, wp_wcs3_schedule.weekday,
wp_wcs3_schedule.start_hour, wp_wcs3_schedule.end_hour
FROM wp_wcs3_schedule
INNER JOIN wp_posts
WHERE wp_wcs3_schedule.class_id = wp_posts.ID
AND wp_wcs3_schedule.weekday >=5
AND wp_wcs3_schedule.start_hour > '09:00:00'
AND wp_posts.post_title NOT LIKE '%squash%'
AND wp_posts.post_title NOT LIKE '%sal%'
ORDER BY wp_wcs3_schedule.weekday, wp_wcs3_schedule.start_hour ASC LIMIT 0,3发布于 2014-03-07 13:39:10
你可以用OR轻松地完成这个任务,所以
AND ( wp_wcs3_schedule.weekday > 5 OR wp_wcs3_schedule.start_hour > '09:00:00')您已经有了>= 5,所以.weekday将是5或更高,然后这将只对那些工作日== 5的人应用开始时间标准。
SELECT wp_posts.ID, wp_posts.post_title, wp_posts.post_name, wp_wcs3_schedule.weekday,
wp_wcs3_schedule.start_hour, wp_wcs3_schedule.end_hour
FROM wp_wcs3_schedule
INNER JOIN wp_posts
WHERE wp_wcs3_schedule.class_id = wp_posts.ID
AND wp_wcs3_schedule.weekday >=5
AND ( wp_wcs3_schedule.weekday > 5 OR wp_wcs3_schedule.start_hour > '09:00:00')
AND wp_posts.post_title NOT LIKE '%squash%'
AND wp_posts.post_title NOT LIKE '%sal%'
ORDER BY wp_wcs3_schedule.weekday, wp_wcs3_schedule.start_hour ASC LIMIT 0,3https://stackoverflow.com/questions/22251480
复制相似问题