文章详情页
mysql - thinkphp一个查询语句的实现
浏览:143日期: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. docker容器呢SSH为什么连不通呢?2. docker - 各位电脑上有多少个容器啊?容器一多,自己都搞混了,咋办呢?3. debian - docker依赖的aufs-tools源码哪里可以找到啊?4. angular.js使用$resource服务把数据存入mongodb的问题。5. docker-compose中volumes的问题6. 关docker hub上有些镜像的tag被标记““This image has vulnerabilities””7. dockerfile - 为什么docker容器启动不了?8. docker api 开发的端口怎么获取?9. golang - 用IDE看docker源码时的小问题10. docker start -a dockername 老是卡住,什么情况?
排行榜
