tableid name1 a2 b3 c4 c5 b库结构大概这样,这只是一个简单的例子,实际情况会复杂得多。
select *, count(distinct name) from table group by name结果:
id name count(distinct name)1 a 12 b 13 c 1最后一 项是多余的,不用管就行了
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语句(必看)的全部内容了,希望对大家有所帮助,多多支持脚本之家~