首页 > thinkphp一个查询语句的实现

thinkphp一个查询语句的实现

获取catid的个数,获取当state等于2时state的个数,并且还要按照pid分组。

请问一个sql语句怎么实现上面的要求。


m("test")->alias('a')->field("count(catid),(select count(1) from test where state=2 and pid=a.pid)")->group("pid")->select();

sql语句:

SELECT COUNT('catid') WHERE state='2' GROUP BY 'pid';

tp代码:

$model->count('catid')->where('state=2')->group('pid')->select();
【热门文章】
【热门文章】