Let's take a look at the following examples:
Table
ID name
1 a
2 b
3 C
4 C
5 B
The library structure is probably like this, this is just a simple example, the actual situation will be much more complicated.
SELECT *, COUNT (distinct name) from table group by name
Results:
ID Name count (distinct name)
1 a 1
2 B 1
3 C 1
The last one is superfluous, so don't worry about it.
tp2.0 Manual Search consistent operation to see the relevant information
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);
The above is a small series for you to bring the thinkphp in multiple tables in the query to prevent data duplication of the SQL statement (must look) of the entire content, I hope to help you, a lot of support cloud Habitat Community ~