SQL查詢符合條件的記錄的總數


1. select count(*) from table;    //統計元組個數

2. select count(列名) from table;  //統計一列中值的個數

3. select count(*) from table where 字段 = "";  //符合該條件的記錄總數

4. sql_count = "select count(*) from article a where 1=1 ";

//這條語句中a就代表article 這張表,后面可以寫a.字段來代表該表的字段,where 1 = 1,就相當於提供了一個where。因為1=1永遠成立。

 就可以根據是否需要加條件,在該語句后面加and a.字段 = "", 等等。

例:

sql_count = "select count(*) from article a where 1=1 ";
if(!"".equals(title) && title!=null){

sql_count +="and a.a_title like '%"+title+"%'";
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM