Home > PHP Framework > ThinkPHP > body text

Teach you how to convert SQL statements to TP5

藏色散人
Release: 2021-11-19 16:35:50
forward
1548 people have browsed it

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 to TP5

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';
Copy after login

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()
Copy after login

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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!