Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use oinSub syntax in Laravel

Shulou Source: shulou.com Published: 2022-06-03 02:15:05 10月01日 Update

This article introduces the knowledge of "how to use oinSub grammar in Laravel". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

I have a sentence, thinking that the join subquery does not support the writing of the model query. Baidu found that there is a syntax of joinSub, so I hereby record it.

The purpose of the following statement is to take the one with the latest date in the whole table (only the latest when there are duplicates in the same field)

I didn't set the capitalization of the table field. I'm just querying the user.

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 () This is the end of the introduction of $resultIds=Table::query ()-> from ('table as T1')-> joinSub ($subQuery,'t2','t1.id','=','t2.id')-> orderBy ('t1.TotalFundNV grammar grammars')-> pluck ('InvestAdvisorCode')-> toArray () "how to use oinSub Grammar in Laravel". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Grammar query content fields more knowledge sentences crude practical ill-informed the same ill-informed learned and then the user writing just dilemma capitalization reality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft OPPO Reno Apple Linux MySQL