`

Select Count (*)和Select Count(1)以及Select Count(column)的区别

 
阅读更多
一般情况下,两着返回结果是一样的

假如表沒有主键(Primary key), 那么count(1)比count(*)快

如果有主键的話,那主键作为count的条件时候count(主键)最快

如果你的表只有一个字段的话那count(*)就是最快的

count(*) 跟 count(1) 的结果一样,都包括对NULL的统计
count(column) 是不包括NULL的统计
分享到:
评论

相关推荐

    T-SQL高级查询

    select count(*), cid, sex from student group by cid, sex having cid > 1 and max(cid) > 2; Ø 嵌套子查询 子查询是一个嵌套在select、insert、update或delete语句或其他子查询中的查询。任何允许使用表达式的...

    强大的国外注入工具-darkMySQLi.py

    [debug] http://www.rayner.com/products.php?id=22/**/AND/**/1=2/**/UNION/**/SELECT/**/1,concat(0x1e,0x1e,COUNT(*),0x1e,0x20),3,4,5,6,7,8,9 ,10/**/FROM/**/db2889_rayner_en.auth/**/WHERE/**/pass=0x...

    SQL操作全集(非常适合初学者)

    总数:select count * as totalcount from table1 求和:select sum(field1) as sumvalue from table1 平均:select avg(field1) as avgvalue from table1 最大:select max(field1) as maxvalue from table1 ...

    sqlserver自定义函数

    select @m=case when @m between 1 and 3 then 1 when @m between 4 and 6 then 4 when @m between 7 and 9 then 7 else 10 end select @time=datename(year,@date)+'-'+convert(varchar(10),@m)+'-01' ...

    SQLQuery5.sql

    from score a left join ( select a.s_score from Score a group by a.s_score having count(a.s_score)>1 and count(distinct a.c_id) > 1)tt on tt.s_score=a.s_score group by a.s_id select distinct a.s_...

    SQLite3 轻量级数据库及SQL语法指导

    总数:select count(*) from table1; 求和:select sum(field1) from table1; 平均:select avg(field1) from table1; 最大:select max(field1) from table1; 最小:select min(field1) from table1; 排序:select ...

    SQL编写规范(数据库操作规范)

     select count(*) from tab1,tab2 执行时间0.96秒    选择TAB2作为基础表 (不佳的方法)    select count(*) from tab2,tab1 执行时间26.09秒    如果有3个以上的表连接查询,那就需要选择交叉表...

    经典SQL语句大全

    select max(column_b) from tablename group by column1,column2,...) alter table tablename drop column column_b 20、说明:列出数据库里所有的表名 select name from sysobjects where type='U' // U代表用户 21...

    sql经典语句一部分

    select max(column_b) from tablename group by column1,column2,...) alter table tablename drop column column_b 20、说明:列出数据库里所有的表名 select name from sysobjects where type='U' // U代表用户 21...

    数据库操作语句大全(sql)

    select max(column_b) from tablename group by column1,column2,...) alter table tablename drop column column_b 20、说明:列出数据库里所有的表名 select name from sysobjects where type='U' // U代表用户 ...

    超实用sql语句

    select max(column_b) from tablename group by column1,column2,...) alter table tablename drop column column_b 20、说明:列出数据库里所有的表名 select name from sysobjects where type='U' // U代表用户 21...

    经典Sql语句 数据库

    总数:select count as totalcount from table1 求和:select sum(field1) as sumvalue from table1 平均:select avg(field1) as avgvalue from table1 最大:select max(field1) as maxvalue from table1 最小:...

    经典sql语句大全基础篇

    2.SELECT column1, column2, column3 FROM table_name; (查询表中指定列的数据) 3.SELECT * FROM table_name WHERE condition; (查询表中符合条件的数据) 4.SELECT COUNT(*) FROM table_name; (统计表中数据总数)

    SQL语句大全(经典珍藏版)

    总数:select count as totalcount from table1 求和:select sum(field1) as sumvalue from table1 平均:select avg(field1) as avgvalue from table1 最大:select max(field1) as maxvalue from table1 最小:...

    某知名公司内部ORACLE培训资料(如果你看后觉得不行,可以损我,人格担保)

    总数:select count as totalcount from table1 求和:select sum(field1) as sumvalue from table1 平均:select avg(field1) as avgvalue from table1 最大:select max(field1) as maxvalue from table1 最小:...

    MyBatis 简单样例

    <select id="countAll" resultType="int"> select count(*) c from blog; </select> <select id="countSome" resultType="int" parameterType="String"> select count(*) c from blog ; </select> <select ...

    经典全面的SQL语句大全

     总数:select count * as totalcount from table1  求和:select sum(field1) as sumvalue from table1  平均:select avg(field1) as avgvalue from table1  最大:select max(field1) as maxvalue from table...

    数据库工具类DatabaseUtil.java

    * 返回记录总数, 使用方法: getAllCount("SELECT count(ID) from tableName") 2004-06-09 * 可滚动的 Statement 不能执行 SELECT MAX(ID) 之类的查询语句(SQLServer 2000) * * @param sql * 需要执行的 SQL *...

    SQL sever 实训

    SET @X =(SELECT COUNT (*) FROM Product ) PRINT '共有'+convert (char(2),@x)+'种产品。' GO --编写计算n!(n=20)的程序,并显示结果。 DECLARE @X int,@product int SELECT @X=1,@product=1 WHILE @X BEGIN ...

    Oracle事例

    1.增加主键 alter table TABLE_NAME add constraint KEY_NAME primary key (TABLE_COLUMN); 指定表空间 alter table TABLE_NAME add constraint KEY_NAME primary key (TABLE_COLUMN) using index tablespace ...

Global site tag (gtag.js) - Google Analytics