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 ...
随机推荐
- WPF导航总结
使用导航的目的是从一个页面进入到另一个页面.无论是预先决定的线性顺序(向导)还是基于层次的用户驱动程序(大部分网站的形式),或者动态生成的路径,主要有3种方法实现:调用Navigate方法,使用Hyp ...
- win10禁止更新的方法
Windows10强制更新苦恼了很多人,下面提供三种禁止Windows10更新的方法. 禁止Windows update服务 启动任务管理器->选择服务->打开服务. 找到Windows ...
- HTML 引用
关于 HTML 引用: (1) <q> 和 <blockquote> 用于实现长短不一的引用语(2) <q> 用于短的引用,<blockquote> 用 ...
- CMake设置输出目录
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Lib)set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAK ...
- BugHD 与你的应用一起成长
BugHD 新增功能 1.新增安装量.启动量的统计功能 BugHD SDK 1.3.0新增安装量.启动量的统计功能,在崩溃分析页面右上角可看到安装量和启动量. BugHD 体验优化 1.Android ...
- 解决layui下拉选择框只能选择不能手动输入文字
审查元素可以看到,layui的select下拉框是用input和div模拟出来的,所以,如下例子,我的解决方法是:$('.mySelect').find('input').removeAttr(&qu ...
- java 对 汉字排序(按照拼音字母排序)
业务场景: 一个list集合,里面add了若干个实体类,针对该实体类排序的属性为String. 使用技术,自定义list排序(JDK自带),重写Comparator接口的compare方法,汉字转拼音 ...
- No.2 PyQt学习
新增加了状态栏.菜单栏和工具栏,界面如下: 代码如下: # -*- coding: utf-8 -*- import sys from PyQt4 import QtGui, QtCore class ...
- QT之 Hello World
下载…… 我下载的Qt creater 版本为4.2.1,Qt版本为5.8.0 打开QT Creater 1. 新建项目 New Project -> Application -> Q ...
- 【linux系列】配置免密登陆
一.SSH无密码登录原理 此操作是为了搭建hadoop集群进行的操作 Master(NameNode|JobTracker)作为客户端,要实现无密码公钥认证,连接到服务器Salve(DataNode| ...