The followingthinkphp frameworkThe tutorial column will give you a brief introduction on how to convert SQL statements into TP5. I hope it will be helpful to friends in need!
Teach you how to convert SQL statements into TP5?
Specific problem description:
Please help me I converted this native SQL statement into TP5. Thank you! It is Db::('name')->
'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';
implementation method of this chain operation:
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()
Attached is the manual, please read more about the manual https ://www.kancloud.cn/manual/thinkphp5/135180
The above is the detailed content of Teach you how to convert SQL statements to TP5. For more information, please follow other related articles on the PHP Chinese website!