Oracle Function:COUNT
Description
The Oracle/PLSQL COUNT function returns the count of an expression.
|
The COUNT(*) function |
returns the number of rows in a table that satisfy the criteria of the SELECT statement, including duplicate rows and rows containing null values in any of the columns. |
|
If a WHERE clause is included in the SELECT statement, |
COUNT(*) returns the number of rows that satisfy the condition in the WHERE clause. |
|
COUNT(expr) |
returns the number of non-null values that are in the column identified by expr. |
|
COUNT(DISTINCT expr) |
returns the number of unique, non-null values that are in the column identified by expr. |
Syntax
SELECT COUNT(aggregate_expression)
FROM tables
[WHERE conditions];
OR
SELECT expression1, expression2, ... expression_n,
COUNT(aggregate_expression)
FROM tables
[WHERE conditions]
GROUP BY expression1, expression2, ... expression_n;
Parameters or Arguments
|
expression1, expression2, ... expression_n |
Expressions that are not encapsulated within the COUNT function and must be included in the GROUP BY clause at the end of the SQL statement. |
|
aggregate_expression |
This is the column or expression whose non-null values will be counted. |
|
Tables |
The tables that you wish to retrieve records from. There must be at least one table listed in the FROM clause. |
|
WHERE conditions |
Optional. These are conditions that must be met for the records to be selected. |
Only includes NOT NULL Values
Not everyone realizes this, but the COUNT function will only include the records in the count where the value of expression in COUNT(expression) is NOT NULL. When expression contains a NULL value, it is not included in the COUNT calculations.
|
With Single Field |
SELECT COUNT(*) AS "Number of employees" |
|
Using DISTINCT |
SELECT COUNT(DISTINCT department) AS "Unique departments" |
|
Using GROUP BY |
SELECT department, COUNT(*) AS "Number of employees" Because you have listed one column in your SELECT statement that is not encapsulated in the COUNT function, you must use a GROUP BY clause. The department field must, therefore, be listed in the GROUP BY section. |
使用DISTINCT 的方法COUNT函数和NVL函数的区别:
|
NVL |
SELECT DISTINCT NVL(emp_name, 'AAA') |
|
COUNT |
SELECT COUNT(DISTINCT department) AS "Unique departments" |
Oracle Function:COUNT的更多相关文章
- Oracle Function: NVL
Description The Oracle/PLSQL NVL function lets you substitute a value when a null value is encounter ...
- Oracle Function:TO_CHAR
Description The Oracle/PLSQL TO_CHAR function converts a number or date to a string.将数字转换为日期或字符串 Syn ...
- oracle function学习1
oracle function学习基层: 函数就是一个有返回值的过程. 首先 知道oracle 使用限制: 函数调用限制: 1. SQL语句中只能调用存储函数(服务器端),而不能调用客户端 ...
- PHP基础语法: echo,var_dump, 常用函数:随机数:拆分字符串:explode()、rand()、日期时间:time()、字符串转化为时间戳:strtotime()可变参数的函数:PHP里数组长度表示方法:count($attr[指数组]);字符串长度:strlen($a)
PHP语言原理:先把代码显示在源代码中,再通过浏览器解析在网页上 a. 1.substr; //用于输出字符串中,需要的某一部分 <?PHP $a="learn php"; ...
- Oracle维护:每天的工作
Oracle维护:每天的工作 检查数据库状态 确认所有的INSTANCE状态以及listener状态正常,登陆到所有数据库或例程,检测ORACLE后台进程: $ ps –ef|grep ora $ l ...
- Oracle ORA-12541:TNS:无监听程序
Oracle ORA-12541:TNS:无监听程序 标签: Oracle DataBase 今天使用Oracle数据库,使用可视化连接工具连接测试环境的数据库时提示无监听程序,最后在老师帮助下终于搞 ...
- 【转载】Oracle递归查询:使用prior实现树操作【本文出自叶德华博客】
本文标题:Oracle递归查询:使用prior实现树操作 本文链接:http://yedward.net/?id=41 本文版权归作者所有,欢迎转载,转载请以文字链接的形式注明文章出处. Oracle ...
- Oracle错误:ORA-01033
Oracle错误:ORA-01033 错误编码:ORA-01033: ORACLE initialization or shutdown in progress 故障描述:因为移动了数据库文件([NA ...
- lintcode :Count 1 in Binary 二进制中有多少个1
题目: 二进制中有多少个1 49% 通过 计算在一个 32 位的整数的二进制表式中有多少个 1. 样例 给定 32 (100000),返回 1 给定 5 (101),返回 2 给定 1023 (111 ...
随机推荐
- 用python开发android应用 【转载】
用python开发android应用 [转载] 转载自:http://www.miui.com/thread-995114-1-1.html Python是动态语言,比较简洁.Android不直接支持 ...
- NetBpm XML解读(5)
原文: nPdl的翻译 在看NetBPM的nPdl文档时做了个翻译,一来是让自己能更好的理解nPdl,二来是希望能得到关心NetBPM的同志的指导. 由于对工作流不熟悉,所以有不少术语翻译没有把 ...
- 基于net.tcp的WCF配置实例解析(转)
http://www.cnblogs.com/scy251147/archive/2012/11/23/2784902.html 原文 本文主要通过文件配置来讲解如何编写一个基于net.tcp的Win ...
- MHL相关资源链接
http://www.mhlconsortium.org/ 消费者网站: www.meetmhl.com采用者网站:www.mhltech.org 博客http://blog.sina.com.cn/ ...
- Kafka manager安装 (支持0.10以后版本consumer)
下载地址: https://pan.baidu.com/s/1jIE3YL4 步骤: 1. 解压kafka-manager-1.3.2.1.zip 2. cd kafka-manager-1.3.2 ...
- 《转》Python学习(17)-python函数基础部分
http://www.cnblogs.com/BeginMan/p/3171977.html 一.什么是函数.方法.过程 推荐阅读:http://www.cnblogs.com/snandy/arch ...
- 字符串处理总结之一(C#String类)
C#(静态String类) C#中提供了比较全面的字符串处理方法,很多函数都进行了封装为我们的编程工作提供了很大的便利.System.String是最常用的字符串操作类,可以帮助开发者完成绝大部分的字 ...
- Post Office Protocol --- pop协议
https://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol
- ftp主动与被动模式区别
FTP是仅基于TCP的服务,不支持UDP.与众不同的是FTP使用2个端口,一个数据端口和一个命令端口(也可叫做控制端口).通常来说这两个端口是21(命令端口)和20(数据端口).但FTP工作方式的不同 ...
- 使用 Gogs 搭建自己的 Git 服务器
安装过程分为这些步骤: 新建用户: 下载源码编译 / 下载预编译二进制打包: 运行安装: 配置调整: 配置 nginx 反向代理: 保持服务运行: 注意,这里默认你已经安装好了 MySQL 服务器和 ...