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 ...
随机推荐
- 一份比较全面的PHP开发编码规范.
这些年来多从事Linux下PHP和C相关的开发,带过很多项目和团队,下面是根据经验整理的PHP编码规范,可以用作给大家的范例和参考,根据需要进行取舍和修改! (可能最新的一些php5的规范不够完整,今 ...
- mongodb 按照时间聚类 java
当存储到mongodb中的是string类型的时间,小tips: 1. 那么在对此域按照时间聚类(每周,每月)时就不能直接使用mongodb的time关键字了,因为mongodb有自己的时间类型,且目 ...
- 【ArcGIS】Web AppBuilder For ArcGIS 配置使用
一.Portal注册 2.Web AppBuilder配置 输入https://XXXX.YYYY.com.cn:3344/webappbuilder/打开配置界面 填写Portal的Url和AppI ...
- Bypass ngx_lua_waf SQL注入防御(多姿势)
0x00 前言 ngx_lua_waf是一款基于ngx_lua的web应用防火墙,使用简单,高性能.轻量级.默认防御规则在wafconf目录中,摘录几条核心的SQL注入防御规则: select.+ ...
- std::string与std::wstring互相转换
作者:zzandyc来源:CSDN原文:https ://blog.csdn.net/zzandyc/article/details/77540056 版权声明:本文为博主原创文章,转载请附上博文链接 ...
- ASP.NET MVC入门到精通——第一个ASP.NET MVC程序
开发流程 新建Controller 创建Action 根据Action创建View 在Action获取数据并生产ActionResult传递给View. View是显示数据的模板 Url请求→Cont ...
- 使用react进行父子组件传值
在单页面里面,父子组件传值是比较常见的,之前一直用vue开发,今天研究了一下react的父子组件传值,和vue差不多的思路,父组件向子组件传值,父通过初始state,子组件通过this.props进行 ...
- codeforces水题100道 第二十三题 Codeforces Beta Round #77 (Div. 2 Only) A. Football (strings)
题目链接:http://www.codeforces.com/problemset/problem/96/A题意:判断一个0-1字符串中出现的最长的0字串或者1字串的长度是否大于等于7.C++代码: ...
- 节日换肤通用技术方案__iOS端实现
一.问题的提出 不知道大家有没有发现, 元旦期间, 很多APP界面里的图标都换成了具有节日气氛的样式, 而在过了元旦节之后, 这些图标又悄无声息的变回了本来的面貌. 这些具有短暂生命周期.而又必须在固 ...
- (原创)Windows下使用android ADT工具dmtracedump.exe绘图
在windows下使用dmtracedump绘图时,出现如下错误: 'dot' 不是内部或外部命令,也不是可运行的程序 或批处理文件. 应该是没有dot这个执行程序,安装:Graphviz程序,然后将 ...