我在下面有一个Query构建器语句,我想为查询引入另一个条件。但是,我无法做到这一点。
此查询正常;
$content = DB::table('subscribed_services as a')
->join('scheduled_messages as b', 'a.id', '=', 'b.subscribed_services_id')
->join('subscription_services_msisdn as c', 'a.id', '=', 'c.subscribed_services_id')
->whereRaw('DATE(b.scheduled_at) = CURDATE()')
->selectRaw('b.message, c. phone_number, a.username, a.password')
->distinct()
->get();
我想介绍另一个where声明;这个->whereRaw('DATE(c.sent_time) != CURDATE()')
。这意味着上面的查询应该只选择其中subscription_services_msisdn.sent_time DATE(c.sent_time)不等于当前日期CURDATE()的值。
任何人都把我带到这里。问候。
答案 0 :(得分:2)
您可以根据需要链接任意数量的条件,因此只需在链中添加另一个whereRaw
:
$content = DB::table('subscribed_services as a')
->join('scheduled_messages as b', 'a.id', '=', 'b.subscribed_services_id')
->join('subscription_services_msisdn as c', 'a.id', '=', 'c.subscribed_services_id')
->whereRaw('DATE(b.scheduled_at) = CURDATE()')
->whereRaw('DATE(c.sent_time) <> CURDATE()')
->selectRaw('b.message, c. phone_number, a.username, a.password')
->distinct()
->get();