Mysql 如何在cakephp中从表中获取行数
我有两张桌子:Mysql 如何在cakephp中从表中获取行数,mysql,cakephp,Mysql,Cakephp,我有两张桌子: id category status 1 test 1 2 test1 1 3 test2 1 这是group\u master表 groupid groupname groupmaster 1 yy 1 2 xx 1 3 yyyy 1 4 xrx
id category status
1 test 1
2 test1 1
3 test2 1
这是group\u master
表
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
这是membergroup
表
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
group\u master.id
与membergroup.groupmaster
中的相同。我希望从第一个表中获取每一行,也希望从第二个表中获取计数
这意味着:
id category status Count
1 test 1 4
2 test1 1 3
3 test2 1 1
这就是我想要得到的结果
如何在Cakephp中使用分页实现这一点?试试以下方法:
您需要加入两个表,并按分组
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