一個表xpf_categories??一個表xpf_log 原生態(tài)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();
發(fā)表評論