文章详情页
mysql - thinkphp一个查询语句的实现
问题描述
获取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. python相关问题求解决,有偿2. javascript - input输入框触发change事件后,外部元素会被选中3. python - 用__call__ 实现装饰器功能4. javascript - 把字符串日期转换成一般时间格式后,发现小于10的数字不会自动添加0在前面,如下5. javascript - 在sublime中如何给.vue文件注释?6. javascript - js判断一个数组是否重复7. python - 请问用cxfreeze打包的可执行程序能反编译出源码么?8. javascript - vue2.0中router.repalce跟router.push有什么区别,二者的应用场景是会有怎样的区别?9. javascript - 这种上传图片预览怎么做?10. javascript - prismplayer播放器全屏问题
排行榜