1

I have two tables:

id  category    status
1   test        1
2   test1       1
3   test2       1

This is the group_master table.

groupid     groupname   groupmaster 
1           yy          1
2           xx          1
3           yyyy                1
4           xrx         1
5           yy          2
6           xx          2
7           yyyy                2
8           xfgdrx              3

This is the membergroup table.

The group_master.id is same as in membergroup.groupmaster.That menas i want to get each row from first table and also want to get the count from second table

That means:

id  category    status  Count
1   test        1       4
2   test1       1       3
3   test2       1       1

This is the result i want to get.

How can i do this in Cakephp with pagination ?

4

1 回答 1

2

尝试这个:

您需要加入两个表并执行GROUP BY

SELECT g.id,g.category,g.status,count(*) as Count
FROM   group_master g
JOIN   membergroup m
ON     g.id=m.groupmaster
GROUP BY g.id,g.category,g.status


SQL 小提琴演示

于 2012-11-06T08:06:53.800 回答