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 ...
随机推荐
- ios开发之--令UITableView滚动到指定位置
这个应用场景还是挺多的,代码如下: //获取到需要跳转位置的行数 NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow: inSect ...
- PostgreSQL逻辑复制之slony篇
Slony是PostgreSQL领域中最广泛的复制解决方案之一.它不仅是最古老的复制实现之一,它也是一个拥有最广泛的外部工具支持的工具,比如pgAdmin3.多年来,Slony是在PostgreSQL ...
- Win10 如何安装 Ubuntu
在 Microsoft Store 中安装 Ubuntu ( 如下图1 ) 把开发者模式打开 ( 如下图2 ) 把 WSL ( Windows下的Linux子系统 ) 打开并重启电脑 ( 如下图3 )
- [JS] console.time() - 计时器构造函数及如何计时
概述 使用计时器可以对代码运行过程进行测速.你可以给每个计时器取一个名字,每个页面上最多可以运行一万个计时器.当你使用计时器名字调用 console.timeEnd() 函数时,浏览器会返回一个毫秒值 ...
- [XPath] XPath 与 lxml (四)XPath 运算符
XPath 中支持的运算符 # | 或: 返回所有 price 和 title 节点集合 >>> root.xpath('//price|//title') [<Element ...
- python--Anaconda学习笔记
http://study.163.com/course/courseLearn.htm?courseId=1003664056#/learn/video?lessonId=1048567028& ...
- 使用createprocess()创建进程打开其他文件方法
#include "stdafx.h"#include "windows.h"#include <iostream>#include "s ...
- Cent OS 常用命令搜集
打开一个 Shadowsocks 配置文件nano /etc/shadowsocks.json 重启 Shadowsocks/etc/init.d/shadowsocks restart centos ...
- Repeater嵌套绑定Repeater以及内层调用外层数据
aspx: <table border=" style="margin-bottom: 5px" width="100%"> <as ...
- C#生成随机验证码例子
C#生成随机验证码例子: 前端: <tr> <td width=" align="center" valign="top"> ...