PHP开发实例大全(提高卷) 中文完整pdf扫描版[244MB]
一个表xpf_categories 一个表xpf_log
原生态sql:
select xpf_categories.*,count(xpf_log.categoryid) as num from xpf_categories left join xpf_log on xpf_categories.id=xpf_log.categoryid group by xpf_categories.id;
thinkphp 下:
$categories=M("Categories");
$category=$categories->table('xpf_categories')->join('xpf_log on xpf_categories.id=xpf_log.categoryid')->field('xpf_categories.*,count(xpf_log.categoryid) as artnum')->group('xpf_log.categoryid')->select();
转载请注明:谷谷点程序 » thinkphp left join查询