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

  • 相关阅读:
    Arch Linux 安装 ibus-rime
    macOS安装Python MySQLdb
    CentOS 7 安装 gcc 4.1.2
    Windows 10安装Python 2.7和MySQL-python
    小米Air安装Arch Linux之图形界面配置(Gnome 和 sway)持续更新中……
    小米Air 13.3 安装Arch Linux
    Linux Shell脚本攻略总结(1)
    Ubuntu下删除配置错误或者失败的安装包
    oProfile的安装与使用
    动态链接库VS静态链接库
  • 原文地址:https://www.cnblogs.com/agang-php/p/8057478.html
Copyright © 2011-2022 走看看