文章详情页
mysql - thinkphp一个查询语句的实现
浏览:108日期: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. list - python 求助2. python - TypeError: tryMsgcode() takes exactly 2 arguments (0 given)3. extra没有加载出来4. javascript - 弹出一个子窗口,操作之后关闭,主窗口会得到相应的响应,例如网站的某些登录界面,django后台的管理等,这是怎么实现的呢?5. javascript - react,获取radio的值出错6. html5 - H5页面唤起APP导航7. 求救一下,用新版的phpstudy,数据库过段时间会消失是什么情况?8. mysql replace 死锁9. linux - Ubuntu下编译Vim8(+python)无数次编译失败10. 环境搭建 - anaconda 创建python2.7环境中打开编译器确是3.6版本
排行榜
