[英]Laravel Eloquent ORM query
I have been trying this mysql query to convert into laravel query but I am unable to figure it out. 我一直在尝试将此mysql查询转换为laravel查询,但无法弄清楚。
SELECT max(a.date) as max FROM table1 a, table2 b where
a.publishing_time<='2015-02-27 12:30:00' and a.Status='1' and
a.id=b.table1_id
table 1 fields are:- 表1的字段是:
sl | date | publishing_time | status
table 2 fields are 表2的字段是
sl | table1_id | additional_fields
I am stucked on this please help me 我被卡住了,请帮助我
Try this Laravel query 试试这个Laravel查询
DB::table('table1 as a')
->select(DB::raw('max(a.date) as max_date'))
->join('table 2 as b', 'a.id', '=', 'b.table1_id')
->where('a.publishing_time'<='2015-02-27 12:30:00')
->where(Status='1')
->get();
Try this.. 尝试这个..
This is laravel join query 这是laravel联接查询
$resource = DB::table('table1')->join('table2', 'table1.id', '=', 'table2.table1_id')->where('table1.publishing_time','<=','2015-02-27 12:30:00')->where('table1.Status','1');
尝试类似:
DB::table('table a as a')->join('table b as b', 'a.id', '=', 'b.table1_id')->max('a.data as max')->where('a.publishing_time', '<=', '2015-02-27 12:30:00')->where('a.status', 1)->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.