文章詳情頁(yè)
mysql - thinkphp一個(gè)查詢(xún)語(yǔ)句的實(shí)現(xiàn)
瀏覽:195日期:2022-06-19 13:09:03
問(wèn)題描述

獲取catid的個(gè)數(shù),獲取當(dāng)state等于2時(shí)state的個(gè)數(shù),并且還要按照pid分組。
請(qǐng)問(wèn)一個(gè)sql語(yǔ)句怎么實(shí)現(xiàn)上面的要求。
問(wèn)題解答
回答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語(yǔ)句:
SELECT COUNT(’catid’) WHERE state=’2’ GROUP BY ’pid’;
tp代碼:
$model->count(’catid’)->where(’state=2’)->group(’pid’)->select();
上一條:mysql-配置 - 使用mysqlbinlog恢復(fù),如何確定上個(gè)全備的具體時(shí)間點(diǎn)?下一條:mysql查詢(xún)數(shù)據(jù)并不是輸入數(shù)據(jù)
相關(guān)文章:
1. html5和Flash對(duì)抗是什么情況?2. html5 - datatables 加載不出來(lái)數(shù)據(jù)。3. docker 下面創(chuàng)建的IMAGE 他們的 ID 一樣?這個(gè)是怎么回事????4. 利用IPMI遠(yuǎn)程安裝centos報(bào)錯(cuò)!5. node.js - mongodb查找子對(duì)象的名稱(chēng)為某個(gè)值的對(duì)象的方法6. 運(yùn)行python程序時(shí)出現(xiàn)“應(yīng)用程序發(fā)生異常”的內(nèi)存錯(cuò)誤?7. 測(cè)試自動(dòng)化html元素選擇器元素ID或DataAttribute [關(guān)閉]8. javascript - QQ第三方登錄的問(wèn)題9. javascript - 在 model里定義的 引用表模型時(shí),model為undefined。10. spring-mvc - spring-session-redis HttpSessionListener失效
排行榜

熱門(mén)標(biāo)簽
網(wǎng)公網(wǎng)安備