zoukankan      html  css  js  c++  java
  • 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)同时使用distinctcount查询,报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(*)合计返回的是一条记录。

  • 相关阅读:
    Shell使用
    从一道面试题谈linux下fork的运行机制
    老了,问题定位难了,xml编码解析
    javacc
    C++概述
    Notepad++中设置Windows、Unix、Mac三种行尾换行符格式间的转换
    玩转html5(一)-----盘点html5新增的那些酷酷的input类型和属性
    Java Drp项目实战—— 环境搭建
    cocos2d-x游戏开发 跑酷(八) 对象管理 碰撞检測
    电话拨号盘(带触摸振动反馈)
  • 原文地址:https://www.cnblogs.com/agang-php/p/8057478.html
Copyright © 2011-2022 走看看