下面thinkphp框架教程欄目將給大家簡(jiǎn)單介紹下如何把SQL語(yǔ)句轉(zhuǎn)成TP5,希望對(duì)需要的朋友有所幫助!
教你如何把SQL語(yǔ)句轉(zhuǎn)成TP5?
具體問(wèn)題描述:
求大神幫我把這段原生SQL語(yǔ)句轉(zhuǎn)成TP5的謝謝!就是Db::('name')->這種鏈?zhǔn)讲僮鞯?/p>
'select a.id, a.title,a.create_time,a.is_solve,count(b.qid) as answer_count from fa_question a,fa_answer b where a.id=b.qid and a.is_solve=0 group by b.qid order by answer_count DESC LIMIT 6';
實(shí)現(xiàn)方法:
Db::table(['fa_question '=>'a','think_role'=>'b']) ->field('a.id, a.title, a.create_time, a.is_solve, count(b.qid) as answer_count) ->where(' a.id=b.qid and a.is_solve=0') ->group('b.qid') ->order('answer_count desc') ->limit(6) ->select()
附上手冊(cè),多看看手冊(cè)https://www.kancloud.cn/manual/thinkphp5/135180