实验:查询一个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的更多相关文章

  1. 大数据下的Distinct Count(二):Bitmap篇

    在前一篇中介绍了使用API做Distinct Count,但是精确计算的API都较慢,那有没有能更快的优化解决方案呢? 1. Bitmap介绍 <编程珠玑>上是这样介绍bitmap的: B ...

  2. 大数据下的Distinct Count(一):序

    在数据库中,常常会有Distinct Count的操作,比如,查看每一选修课程的人数: select course, count(distinct sid) from stu_table group ...

  3. MongoDB学习笔记——聚合操作之group,distinct,count

    单独的聚合命令(group,distinct,count) 单独聚合命令 比aggregate性能低,比Map-reduce灵活度低:但是可以节省几行javascript代码,后面那句话我自己加的,哈 ...

  4. Sql优化(二) 快速计算Distinct Count

    原创文章,始发自本人个人博客站点,转载请务必注明出自http://www.jasongj.com 个人博客上本文链接http://www.jasongj.com/2015/03/15/count_di ...

  5. SSAS 度量值中的distinct count局聚合方式会数为null的值

    我们来看一个例子 Analysis Services: For Distinct Count measure NULL = 0 If you are to look at the table of v ...

  6. nyoj 975 Distinct Count

    Distinct Count 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 给一个长度为 n 的数列 {an} ,找出有多少个长度为 m 的区间,使区间中不含有重复的数 ...

  7. sql中Distinct&Count的用法

    Distinct作用:消除重复的数值 1.如: select id from T1 select distinct id from T1 二者的检索效果如下: distinct可以用来修饰多列,如: ...

  8. 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 ...

  9. ElasticSearch中"distinct","count"和"group by"的实现

    最近在业务中需要使用ES来进行数据查询,在某些场景下需要对数据进行去重,以及去重后的统计.为了方便大家理解,特意从SQL角度,方便大家能够理解ES查询语句. 1 - distinct ; { &quo ...

随机推荐

  1. mysql的root的权限被控制无法授权

    一.环境: MariaDB [(none)]> select version(); +----------------+ | version()      | +---------------- ...

  2. Bat脚本实现监控进程功能

    脚本不间断监控notepad.exe进程是否执行,若停止,则自动重启该进程,程序如下: @echo off set _task = notepad.exe set _svr = c:\windows\ ...

  3. 最小生成树(prime算法 & kruskal算法)和 最短路径算法(floyd算法 & dijkstra算法)

    一.主要内容: 介绍图论中两大经典问题:最小生成树问题以及最短路径问题,以及给出解决每个问题的两种不同算法. 其中最小生成树问题可参考以下题目: 题目1012:畅通工程 http://ac.jobdu ...

  4. 【CF914G】Sum the Fibonacci 快速??变换模板

    [CF914G]Sum the Fibonacci 题解:给你一个长度为n的数组s.定义五元组(a,b,c,d,e)是合法的当且仅当: 1. $1\le a,b,c,d,e\le n$2. $(s_a ...

  5. Linguistic Data Consortium (LDC)

    搞NLP的人经常会听到一个神秘的名字LDC,因为大量的论文所使用的数据都来自于LDC,本文就来揭露其神秘面目. About LDC: LDC,全名Linguistic Data Consortium, ...

  6. iOS - 开发一套代码多个app展示不同图标和名称

    引言 公司项目重构之后,有了相对比较完善的开发体系,首先git分支分为日常.预发.生产三个主要分支,开发阶段都在日常(daily)分支下开相应功能的feature分支,开发完再合并. 我的iOS工程需 ...

  7. nginx动静分离小示例

    server { listen ; server_name www.xxx.cn; #静态页面 #匹配首页,url:www.xxx.cn index index.html; root /usr/loc ...

  8. /usr/bin/ld: i386:x86-64 architecture of input file `command.o' is incompatible with i386 output

    /usr/bin/ld: i386:x86-64 architecture of input file `command.o' is incompatible with i386 output 出现这 ...

  9. python---使用pycharm运行py文件

    在pycharm中新建一个.py的文件,那么如何使用pycharm来运行这个文件呢? 第一步:选择这个三角(即Edit configuration)进入设置 第二步:设置文件名和路径 第三步:设置完成 ...

  10. 2018C语言第二次作业

    一.学习内容总结 1.指针是一种数据类型,同样占有空间,其存储的是内存地址: 2.定义指针变量要在变量名之前加“*”字符表示: 3.“&”是取地址运算符,“*”是间接运算符: (注:声名和使用 ...