文章詳情頁
mysql - thinkphp一個(gè)查詢語句的實(shí)現(xiàn)
瀏覽:116日期:2022-06-19 13:09:03
問題描述
獲取catid的個(gè)數(shù),獲取當(dāng)state等于2時(shí)state的個(gè)數(shù),并且還要按照pid分組。
請(qǐng)問一個(gè)sql語句怎么實(shí)現(xià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語句:
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查詢數(shù)據(jù)并不是輸入數(shù)據(jù)
相關(guān)文章:
1. mysql - 表名稱前綴到底有啥用?2. 致命錯(cuò)誤: Class ’appfacadeTest’ not found3. 老師們php,插入數(shù)據(jù)庫mysql,都是空的,要怎么解決4. 求大神支招,php怎么操作在一個(gè)html文件的<head>標(biāo)記內(nèi)添加內(nèi)容?5. php點(diǎn)贊一天一次怎么實(shí)現(xiàn)6. 怎么php怎么通過數(shù)組顯示sql查詢結(jié)果呢,查詢結(jié)果有多條,如圖。7. PHP類屬性聲明?8. sql語句 - 如何在mysql中批量添加用戶?9. phpstady在win10上運(yùn)行10. 在應(yīng)用配置文件 app.php 中找不到’route_check_cache’配置項(xiàng)
排行榜

熱門標(biāo)簽