使用tp,group和count无法得到想要的sql语句。
D('Report')->group('begin')->where($term)->count(); z();
SELECT COUNT(*) AS tp_count FROM `qdb_report` WHERE ( `type` = 1 ) AND ( `branch` = 59 ) GROUP BY begin LIMIT 1
改成子查询:
$subQuery = D('Report')->group('begin')->where($term)->select(false); $data['rows'] = D('Report')->table($subQuery . ' a')->count();
SELECT COUNT(*) AS tp_count FROM ( SELECT * FROM `qdb_report` WHERE ( `type` = 1 ) AND ( `branch` = 59 ) GROUP BY begin ) a LIMIT 1
得到分组后的总条数。