mysql - laravel 子查詢的問題
問題描述
要拼成如下語(yǔ)句:
select field1,field2,field3 from table1 inner join (select id from table1 where field4=$field4 limit 100, 20) as temp using(id)
laravel 改怎么寫?···嘗試了許多都不行
感謝~
問題解答
回答1:直接用Laravel的ORM是無法實(shí)現(xiàn)的,至少是目前無法實(shí)現(xiàn),所以這種需求還是乖乖用DB類提供的原生SQL方式吧,比如用DB::select等。
也可以參考一下這個(gè)Laravel 5. Using the USING operator,跟你一樣的需求。
這里有一個(gè)pull請(qǐng)求,為L(zhǎng)aravel添加對(duì)using的支持,不過貌似因?yàn)闆]有添加相應(yīng)的單元測(cè)試被拒了。
回答2:$courses = Orgcourse::where(’classify’,’=’,$num)->join(’collections’,’orgcourses.id’,’=’,’collections.cid’)->select(DB::raw(’*,orgcourses.id as o_id,collections.id as c_id’))->orderBy(’collections.created_at’,’desc’)->paginate(2);類似于這種,能查出來,但是有點(diǎn)繁瑣好像,關(guān)聯(lián)查詢
相關(guān)文章:
1. boot2docker無法啟動(dòng)2. docker-compose中volumes的問題3. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””4. docker容器呢SSH為什么連不通呢?5. java - SSH框架中寫分頁(yè)時(shí)service層中不能注入分頁(yè)類6. dockerfile - 為什么docker容器啟動(dòng)不了?7. 關(guān)于docker下的nginx壓力測(cè)試8. node.js - antdesign怎么集合react-redux對(duì)input控件進(jìn)行初始化賦值9. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.10. nignx - docker內(nèi)nginx 80端口被占用

網(wǎng)公網(wǎng)安備