【问题标题】:Laravel Eloquent ORM queryLaravel Eloquent ORM 查询
【发布时间】:2015-02-27 12:53:08
【问题描述】:

我一直在尝试将此 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

表 1 的字段是:-

 sl | date | publishing_time | status

表 2 字段是

 sl | table1_id | additional_fields

我被困在这个问题上,请帮助我

【问题讨论】:

  • 您是在使用模型还是想使用 DB 类?

标签: php mysql laravel-4 controller laravel-5


【解决方案1】:

试试这个 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();

【讨论】:

    【解决方案2】:

    试试这个..

    这是 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');
    

    【讨论】:

      【解决方案3】:

      尝试类似:

      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();
      

      【讨论】:

      • 复制第一个答案
      猜你喜欢
      • 2015-01-21
      • 1970-01-01
      • 1970-01-01
      • 2015-12-06
      • 2016-06-13
      • 1970-01-01
      • 2015-05-16
      • 2019-03-15
      • 2015-04-09
      相关资源
      最近更新 更多