下面由laravel教程栏目带大家介绍关于laravel joinsub的使用,希望对大家有所帮助!
我有个语句,想着以为 join 子查询不支持改成模型查询的写法呢,百度了下,发现有 joinsub 的语法,在下孤陋寡闻了,特此记录
以下语句目的是,取全表最新日期的那条(相同字段中有重复时,只取最新)
表字段大写不是我定的~我只是查询使用者
$resultids = db::connection('fund')->select("select t1.investadvisorcodefrom table t1 inner join ( select substring_index( group_concat( id order by enddate desc ), ',', 1 ) as id from table t2 group by investadvisorcode ) t2 on t1.id = t2.idorder by t1.totalfundnv desc");
$subquery = table::query() ->selectraw("substring_index( group_concat( id order by enddate desc ), ',', 1 ) as id") ->from('table as t2') ->groupby('investadvisorcode') ->getquery(); $resultids=table::query() ->from('table as t1') ->joinsub($subquery,'t2','t1.id','=','t2.id') ->orderby('t1.totalfundnv','desc') ->pluck('investadvisorcode')->toarray()
相关推荐:最新的五个laravel视频教程以上就是laravel中居然有个joinsub的语法?的详细内容。