以优雅的方式撰写这个句子的技巧
P粉025632437
P粉025632437 2023-09-07 18:25:04
0
1
633

我有两个表ParametersShare_Details。我在这里有我的原始SQL查询,我想以纯粹的Eloquent方式编写它。请帮忙。

$shareDetails=DB::select
              ("SELECT s.id,
                       share_type,
                       para_int_1,
                       para_int_2,
                       price,
                       para_name 
             FROM share_details as s,parameters 
                  where para_type='share'
                    and para_id=share_type
                    and startDate=(select max(startdate) 
                                   from share_details 
                                   where share_type=s.share_type)
              group by share_type,
                       s.id,
                       para_int_1,
                       para_int_2,
                       price,
                       para_name");

P粉025632437
P粉025632437

全部回复(1)
P粉459440991

尝试像这样:

DB::table('share_details')
->crossJoin('parameters'
->select('share_details.id', 'share_type', 'para_int_1', 'para_int_2', 'price', 'para_name')
->where('para_type','=','share')
->where('para_id','=',DB::raw('share_type'))
->where('startDate','=',function($query) {
    $query->from('share_details')
        ->select(DB::raw("'max'(startdate))
        ->where('share_type','=',DB::raw('s.share_type'));
})
->groupBy('share_type','share_details.id','para_int_1','para_int_2','price','para_name')
->get();
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板