下面先来看看例子:
table
id name
1 a
2 b
3 c
4 c
5 b
库结构大概这样,这只是一个简单的例子,实际情况会复杂得多。
select *, count(distinct name) from table group by name
结果:
id name count(distinct name)
1 a 1
2 b 1
3 c 1
最后一 项是多余的,不用管就行了
tp2.0手册 搜索连贯操作 可看到相关的资料
select cat_id, count(*) as goods_num from talble group by cat_id
$m = m('table');
$rs = $m->field(array('cat_id','count(*)'=>'goods_num'))->group('cat_id')->select();
echo $m->getlastsql();
print_r($rs);
以上就是小编为大家带来的thinkphp中多表查询中防止数据重复的sql语句(必看)的全部内容了,希望对大家有所帮助,多多支持硕编程~
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!