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(*)合计返回的是一条记录。

  • 相关阅读:
    Python基础06 循环
    Python基础04 运算
    Python基础02 基本数据类型
    Python基础03 序列
    C++ ------ 引用
    C++ ------ 互斥锁、原子操作的性能测试
    Qt ------ 断开某对信号与槽的connect
    5种网络通信设计模型(也称IO模型)
    Qt ------ 主事件循环与 QEventLoop
    Qt ------ 再论事件循环
  • 原文地址:https://www.cnblogs.com/agang-php/p/8057478.html
Copyright © 2011-2022 走看看