distinct count
实验:查询一个column的无重复记录,需要知道有多少条记录,并显示记录。
统计记录用count(*)函数,无重复记录distinct,以emp表为例。
(1)先查询无重复记录
[@more@]
SQL>select distinct emp.sal from scott.emp;
SAL
----------
800
950
1100
1250
1300
1500
1600
2450
2850
2975
3000
SAL
----------
5000
已选择12行。
(2)查询合计记录数
SQL> select count(sal) from scott.emp;
COUNT(SAL)
----------
14
(3)查询无重复记录数
SQL> select count(distinct emp.sal) from scott.emp;
COUNT(DISTINCTEMP.SAL)
------------------
12
(4)同时使用distinct和count查询,报ORA—00937错误:非单组分组函数。需要与group by子句合用才可以。
SQL> select distinct sal ,count(*) from emp;
select distinct sal,count(*) from emp
*
ERROR 位于第 1 行:
ORA-00937: 非单组分组函数
用命令查询显示不同记录、合计相同列数的记录:
SQL> select distinct emp.sal,count(*) from scott.emp group by sal;
SAL COUNT(*)
---------- ----------
800 1
950 1
1100 1
1250 2
1300 1
1500 1
1600 1
2450 1
2850 1
2975 1
3000 2
SAL COUNT(*)
---------- ----------
5000 1
已选择12行。
分析原因:distinct返回是是多条记录;
count(*)合计返回的是一条记录。
distinct count的更多相关文章
- 大数据下的Distinct Count(二):Bitmap篇
在前一篇中介绍了使用API做Distinct Count,但是精确计算的API都较慢,那有没有能更快的优化解决方案呢? 1. Bitmap介绍 <编程珠玑>上是这样介绍bitmap的: B ...
- 大数据下的Distinct Count(一):序
在数据库中,常常会有Distinct Count的操作,比如,查看每一选修课程的人数: select course, count(distinct sid) from stu_table group ...
- MongoDB学习笔记——聚合操作之group,distinct,count
单独的聚合命令(group,distinct,count) 单独聚合命令 比aggregate性能低,比Map-reduce灵活度低:但是可以节省几行javascript代码,后面那句话我自己加的,哈 ...
- Sql优化(二) 快速计算Distinct Count
原创文章,始发自本人个人博客站点,转载请务必注明出自http://www.jasongj.com 个人博客上本文链接http://www.jasongj.com/2015/03/15/count_di ...
- SSAS 度量值中的distinct count局聚合方式会数为null的值
我们来看一个例子 Analysis Services: For Distinct Count measure NULL = 0 If you are to look at the table of v ...
- nyoj 975 Distinct Count
Distinct Count 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 给一个长度为 n 的数列 {an} ,找出有多少个长度为 m 的区间,使区间中不含有重复的数 ...
- sql中Distinct&Count的用法
Distinct作用:消除重复的数值 1.如: select id from T1 select distinct id from T1 二者的检索效果如下: distinct可以用来修饰多列,如: ...
- linq语法之select distinct Count Sum Min Max Avg
原文来自:http://www.50cms.com/Pages_13_72.aspx 本篇详细说明linq中的Select和Count/Sum/Min/Max/Avg等的用法. Select/Dist ...
- ElasticSearch中"distinct","count"和"group by"的实现
最近在业务中需要使用ES来进行数据查询,在某些场景下需要对数据进行去重,以及去重后的统计.为了方便大家理解,特意从SQL角度,方便大家能够理解ES查询语句. 1 - distinct ; { &quo ...
随机推荐
- C# mongohelper的初始化及账户密码设置
MongoClientSettings mongoSettings = new MongoClientSettings(); TimeSpan t = ); mongoSettings.Connect ...
- LeetCode 46 Permutations(全排列问题)
题目链接:https://leetcode.com/problems/permutations/?tab=Description Problem:给出一个数组(数组中的元素均不相同),求出这个数组 ...
- linux下MySQL安装及设置(二)
MySQL二进制分发包安装 去MySql官网下MySQL classic版mysql-5.6.30-osx10.11-x86_64.tar.gz http://dev.mysql.com/downl ...
- github的README.md文件格式
一.在线编辑器:stackedit 网址:https://stackedit.io/ README.md是使用Markdown语法.基本规则如下: Markdown 语法速查表 1 标题与文字格式 标 ...
- Unity3D Shader落雪效果
Shader "Custom/Snow" { Properties { _MainTex ("Base (RGB)", 2D) = "white&qu ...
- SocketAsyncEventArgs的释放问题
起因是发现一个同事编写的程序运行两个月左右,占用了服务器20G左右的内存.用WinDbg查看发现存在大量的Async Pinned Handles,而它们的gcroot都来自于SocketAsyncE ...
- 简单ORM工具的设计和编写,自己项目中曾经用过的
http://www.cnblogs.com/szp1118/archive/2011/03/30/ORM.html 在之前的一个项目中自己编写了一个简单的ORM小工具,这次重新整理和重构了一下代码, ...
- python unittest框架中addCleanup函数详解
接上一篇doCleanups说明,这次介绍下另一个很好用的函数:addCleanup 还是老规矩,看官方文档说明: addCleanup(function, *args, **kwargs)¶ Add ...
- webp图片优化
根据对目前国内浏览器占比与 WebP 的兼容性分析,大约有 50% 以上的国内用户可以直接体验到 WebP,如果你的网站以图片为主,或者你的产品基于 Chromium 内核,建议体验尝试.假如你打算在 ...
- logstash实战filter插件之grok(收集apache日志)
有些日志(比如apache)不像nginx那样支持json可以使用grok插件 grok利用正则表达式就行匹配拆分 预定义的位置在 /opt/logstash/vendor/bundle/jruby/ ...