文章详情页
mysql - thinkphp一个查询语句的实现
浏览:191日期:2022-06-19 13:09:03
问题描述

获取catid的个数,获取当state等于2时state的个数,并且还要按照pid分组。
请问一个sql语句怎么实现上面的要求。
问题解答
回答1:m('test')->alias(’a’)->field('count(catid),(select count(1) from test where state=2 and pid=a.pid)')->group('pid')->select();回答2:
sql语句:
SELECT COUNT(’catid’) WHERE state=’2’ GROUP BY ’pid’;
tp代码:
$model->count(’catid’)->where(’state=2’)->group(’pid’)->select();
相关文章:
1. dockerfile - [docker build image失败- npm install]2. docker gitlab 如何git clone?3. docker网络端口映射,没有方便点的操作方法么?4. docker api 开发的端口怎么获取?5. docker-compose中volumes的问题6. mysql - phpmyadmin怎么分段导出数据啊?7. boot2docker无法启动8. 关docker hub上有些镜像的tag被标记““This image has vulnerabilities””9. dockerfile - 我用docker build的时候出现下边问题 麻烦帮我看一下10. docker不显示端口映射呢?
排行榜

网公网安备