查询符合条件的记录总数的SQL语句如何写?在SQL Server中,我们想要查询记录的总数是比较简单的,用count()函数就可以实现,下面我们要实现的需求是查询符合条件的记录总数,那么这要如何写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+"%'";
}
大型站长资讯类网站! https://www.0833zz.com