目前,我得到了这个:
SELECT `deals`.*, deals_bookings.date AS 'b_date', deals_bookings.id AS 'book_id'
FROM `deals_bookings`
INNER JOIN deals ON (deals.ID = deals_bookings.deal_id)
INNER JOIN users ON (users.id = deals.partner_id)
INNER JOIN deals_bookings_times ON (deals_bookings_times.book_id = deals_bookings.id)
WHERE 1 AND deals_bookings.date = CURDATE() AND users.company_type = 'restaurant'
这会抓取今天有预订日期的交易(CURDATE())。
现在我添加了一个专栏:deals_bookings.everyWeekDay
该列的计划是存储周数 - >在1-7之间,其中1是星期一(星期一),7星是星期日。
纯mysql查询是否有可能选择所有具有deals_bookings.date = CURDATE()的交易或者如果deals_bookings.everyWeekDay =今天的周数?
答案 0 :(得分:1)
你想用
deals_bookings
。everyWeekDay
= WEEKDAY(现在())
但WEEKDAY周一返回 - 0,周日 - 6;所以我们要添加1
结合条件
WHERE (`deals_bookings`.`date` = CURDATE() OR `deals_bookings`.`everyWeekDay` = WEEKDAY(NOW()) + 1 ) AND `users`.`company_type` = 'restaurant'