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 ...
随机推荐
- switch和continue的关系
突然想到 我们用 switch都是用 break return等关键字来配合,有没有一种情况下是用continue呢?而且如果真的出现了continue,结果是什么样的呢?
- lua 根据函数名字符串来执行函数
function myfunction(msg) print("this is msg fun " .. msg); end local fun =_G["myfunct ...
- js精准时间迭代器(定时器)
/** * 精准时间迭代器 * Create By Tujia @2017.05.22 * * 使用示例: * window.setMyInterval(function(){ * console.l ...
- Linux应急响应(一):SSH暴力破解
0x00 前言 SSH 是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议,主要用于给远程登录会话数据进行加密,保证数据传输的安全.SSH口令长度太短或者复杂度不够,如仅包含数字,或仅包 ...
- 【代码审计】后台Getshell的两种常规姿势
0x00 前言 在早些年刚接触web安全的时候,基础套路都是找注入--找后台--找上传点--找数据库备份--Getshell,然而在代码审计的角度,也存在类似的基本操作. 这里结合代码实例介绍白盒Ge ...
- Qt Creator build遇到error lnk1158 无法运行rc.exe
解决办法: 将C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x64 目录下的rc.exe 和rcdll.dll 复制到 C:\Prog ...
- U3D的控制
做游戏少不了控制,但是一个成熟的游戏引擎,是不能简单仅仅获取键盘中或者遥感确定的按键来控制,要考虑到用户更改游戏按键的情况,当然也得考虑到不同设备的不通输入方式,比如U3D是可以运行在iphone上的 ...
- ORACLE常用函数汇总【转】
PL/SQL单行函数和组函数详解 函数是一种有零个或多个参数并且有一个返回值的程序.在SQL中Oracle内建了一系列函数,这些函数都可被称为SQL或PL/SQL语句, 函数主要分为两大类: 单行函数 ...
- 重写MFC窗口上的关闭按钮事件(SDI, MDI, Dialog)
This piece of code demonstrate how to override WM_CLOSE event. 点击窗口关闭按钮,触发相关事件! 有时候,在MFC程序退出之前,我们通常会 ...
- Qt5 教程
序 Qt 前言 Hello, world! 信号槽 自定义信号槽 Qt 模块简介 MainWindow 简介 添加动作 资源文件 对象模型 布局管理器 菜单栏.工具栏和状态栏 对话框简介 对话框数据传 ...