Oracle 中count(1) 和count(*) 的区别
来源:互联网 发布:c语言基础代码 编辑:程序博客网 时间:2024/06/12 19:11
<span style="font-size:18px;">count(1)与count(*)比较: 如果你的数据表没有主键,那么count(1)比count(*)快 如果有主键的话,那主键(联合主键)作为count的条件也比count(*)要快 如果你的表只有一个字段的话那count(*)就是最快的啦 count(*) count(1) 两者比较。主要还是要count(1)所相对应的数据字段。 如果count(1)是聚索引,id,那肯定是count(1)快。但是差的很小的。 因为count(*),自动会优化指定到那一个字段。所以没必要去count(?),用count(*),sql会帮你完成优化的count详解:count(*)将返回表格中所有存在的行的总数包括值为null的行,然而count(列名)将返回表格中除去null以外的所有行的总数(有默认值的列也会被计入).distinct 列名,得到的结果将是除去值为null和重复数据后的结果----------------------------------------------------------------------------------------------------------------举例演示如下:SQL> create table test2 (3 ename varchar2(10),4 sal number(4)5 );表已创建。SQL> insert into test values('fxe1',90);已创建 1 行。SQL> insert into test(ename) values('fxe2');已创建 1 行。SQL> insert into test(ename) values('fxe3');已创建 1 行。SQL> insert into test(ename) values('fxe4');已创建 1 行。SQL> insert into test values('fxe5',80);已创建 1 行。SQL> insert into test values('fxe6',80);已创建 1 行。SQL> select * from test;ENAME SAL---------- ----------fxe1 90fxe2fxe3fxe4fxe5 80fxe6 80SQL> select count(*) from test;COUNT(*)----------6SQL> select count(sal) from test;COUNT(SAL)----------3SQL> select count(distinct sal) from test;COUNT(DISTINCTSAL)------------------2SQL> select distinct sal from test;SAL----------8090 </span>
0 0
- Oracle 中count(1) 和count(*) 的区别
- Oracle 中count(1) 和count(*) 的区别
- Oracle 中count(1) 和count(*) 的区别
- Oracle 中count(1) 和count(*) 的区别
- Oracle 中count(1) 和count(*) 的区别
- Oracle 中count(1) 和count(*) 的区别
- Oracle 中count(1) 和count(*) 的区别
- oracle中关于count(1)、count(*)、count(rowid)、count(某个字段)使用上的区别和性能问题
- oracle中关于count(1)、count(*)、count(rowid)、count(某个字段)使用上的区别和性能问题
- oracle 中sum和count的区别
- oracle 中sum和count的区别
- SQL语句中count(1)和count(*)的区别
- SQL语句中count(1)和count(*)的区别
- count(1)和count(*)的区别
- select count(1)和count(*)的区别
- count(*)和count(1)的区别
- count(*)和count(1)的区别
- count(1)和count(*)的区别
- js 中也是存在关键字的
- GRE写作必备句型
- onmouseover事件中把鼠标变成小手形状
- Joomla!模板如何工作
- Mysql JDBC URL中几个重要参数说明
- Oracle 中count(1) 和count(*) 的区别
- input textarea 限制输入
- C++11 两种新的数组形参使用方式
- PHP没有数据库连接池怎么破?PHP环境下使用Nginx ngx_http_limit_req_module模块的高负载解决方案
- Interlocked Variable Access
- 两个json分组的写法
- java基础入门-对象流与序列化
- 获取屏幕宽高,和dp,px,sp的转化工具类
- java实现中文汉字的首字母排序