文章詳情頁
mysql - thinkphp一個查詢語句的實現
瀏覽:106日期: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. 求救一下,用新版的phpstudy,數據庫過段時間會消失是什么情況?2. python沒入門,請教一個問題3. 小程序怎么加外鏈,語句怎么寫!求救新手,開文檔沒發現4. php如何獲取訪問者路由器的mac地址5. html - 爬蟲時出現“DNS lookup failed”,打開網頁卻沒問題,這是什么情況?6. html5 - input type=’file’ 上傳獲取的fileList對象怎么存儲于瀏覽器?7. 求教一個mysql建表分組索引問題8. node.js - 用nodejs 的node-xlsx模塊去讀取excel中的數據,可是讀取出來的日期是數字,請問該如何讀取日期呢?9. javascript - vue-resource中如何設置全局的timeout?10. javascript - 在 vue里面用import引入js文件,結果為undefined
排行榜
