以下由Laravel教學專欄帶大家介紹關於Laravel joinSub的使用,希望對大家有幫助!
我有個語句,想著以為join
子查詢不支援改成模型查詢的寫法呢,百度了下,發現有joinSub
的語法,在下孤獨寡聞了,特此記錄
以下語句目的是,取全表最新日期的那條(相同字段中有重複時,只取最新)
表格字段大寫不是我定的~我只是查詢用戶
$resultIds = DB::connection('fund')->select(" SELECT t1.InvestAdvisorCode FROM 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.id order 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的語法?的詳細內容。更多資訊請關注PHP中文網其他相關文章!