sql 计数

SQL Distinct keyword is used to select unique set of values for a column in a table.

SQL Distinct关键字用于为表中的列选择唯一的一组值。

SQL不同 (SQL Distinct)

  • It is very often that we have duplicate data available as part of the data storage. For example, as part of an address table, the state column can have the same value multiple times.通常,我们有重复的数据可作为数据存储的一部分。 例如,作为地址表的一部分,状态列可以多次具有相同的值。
  • In such cases when we need to identify the unique set of values we use SQL DISTINCT keyword along with SELECT to identify the unique values.在这种情况下,当我们需要标识唯一值集时,可以使用SQL DISTINCT关键字和SELECT来标识唯一值。
  • SQL DISTINCT looks through the list of values and identifies the unique values from the list.SQL DISTINCT浏览值列表,并从列表中识别唯一值。

SQL选择不同的语法 (SQL Select Distinct Syntax)

SELECT DISTINCT column FROM table_name;

In the syntax above the distinct values are retrieved from the column that is mentioned as part of the query.

在上面的语法中,从查询中提到的列中检索不同的值。

Let’s try to understand the DISTINCT command through some example.

让我们尝试通过一些示例来了解DISTINCT命令。

SQL不同的示例 (SQL Distinct Example)

Let us consider the following Customer Table to understand SQL DISTINCT query.

让我们考虑以下客户表,以了解SQL DISTINCT查询。

CustomerId CustomerName CustomerAge CustomerGender
1 John 31 M
2 Amit 25 M
3 Annie 35 F
顾客ID 顾客姓名 客户年龄 客户性别
1个 约翰 31 中号
2 阿米特 25 中号
3 安妮 35 F

Scenario: Identify unique genders from Customer table.

场景 :从“客户”表中识别唯一的性别。

Query:

查询

SELECT DISTINCT CutomerGender FROM Customer;
CustomerGender
M
F
客户性别
中号
F

SQL计数不同的值 (SQL Count Distinct Values)

Sometimes we want to count the total number of distinct values. For example, find out the count of unique gender in the Customer table. Here we will have to use SQL Count function and distinct clauses together within SQL Select statement. We will use the inner select query to first find out the unique gender values and the use count function on it.

有时我们想计算不同值的总数。 例如,在“客户”表中查找唯一性别的计数。 在这里,我们将必须在SQL Select语句中一起使用SQL Count函数和不同子句。 我们将使用内部选择查询来首先找出唯一的性别值及其上的使用计数功能。

SELECT Count(*) As DistinctGender FROM (SELECT DISTINCT CutomerGender FROM Customer);

带计数SQL不同值 (SQL Distinct Values with Count)

What if we want to find the gender and their count in the customer table. We can achieve this using group by clause with distinct clause and count function.

如果我们想在客户表中找到性别及其数量怎么办。 我们可以使用带有不同子句和计数功能的group by子句来实现此目的。

SELECT DISTINCT CustomerGender, Count(*) as Occurs FROM Customer GROUP BY CustomerGender;
CustomerGender Occurs
M 2
F 1
客户性别 发生
中号 2
F 1个

That’s all for SQL Distinct clause with examples. If you are looking for any specific scenario, please comment and I will try to respond with the solution.

这就是带有示例SQL Distinct子句的全部内容。 如果您正在寻找任何特定的情况,请发表评论,我将尝试以解决方案做出回应。

翻译自: https://www.journaldev.com/18669/sql-distinct-count-select

sql 计数

sql 计数_SQL不同,SQL计数不同,SQL选择不同相关推荐

  1. mysql高效率sql统计_SQl多表查询优化 高效率SQL语句

    这个功能大大地提高了SQL的执行性能并节省了内存的使用:我们发现,单表数据的统计比多表统计的速度完全是两个概念.单表统计可能只要0.02秒,但是2张表联合统计就可能要几十表了.这是因为ORACLE只对 ...

  2. sql计数_SQL计数区分功能概述

    sql计数 This article explores SQL Count Distinct operator for eliminating the duplicate rows in the re ...

  3. navicat循环执行上下两行相减sql语句_SQL语句的优化分析

    一.开门见山,问题所在 sql语句性能达不到你的要求,执行效率让你忍无可忍,一般会时下面几种情况. 网速不给力,不稳定. 服务器内存不够,或者SQL 被分配的内存不够. sql语句设计不合理 没有相应 ...

  4. java代码转置sql数据_SQL Server中的数据科学:数据分析和转换–使用SQL透视和转置

    java代码转置sql数据 In data science, understanding and preparing data is critical, such as the use of the ...

  5. sql示例_SQL Server Lead功能概述和示例

    sql示例 This article explores the SQL Server Lead function and its usage with various examples. 本文通过各种 ...

  6. hive sql练习_SQL语句+语法 I 数据分析面试必备

    - 点击上方"中国统计网"订阅我吧!- 前些天在网上冲浪的时候看到一个案例咨询,问说世界500强的数据分析要不要去,评论区一片爆炸:"楼主能分享一下文科生怎么转行做数据分 ...

  7. 试图将驱动程序添加到存储区_SQL 已死,但 SQL 将永存!

    (给数据分析与开发加星标,提升数据技能) 编译:CSDN-弯月,作者:Jennifer Ouellette 在 SQL 被引入的 45 年中,它经历了许多数据库的诞生和消亡,也经历了许多数据处理方式的 ...

  8. navicat循环执行上下两行相减sql语句_SQL太难?你离完全理解SQL就差这10步!

    - 点击上方"中国统计网"设置⭐星标不迷路!- 很多程序员视 SQL 为洪水猛兽.SQL 是一种为数不多的声明性语言,它的运行方式完全不同于我们所熟知的命令行语言.面向对象的程序语 ...

  9. sql 百分号_SQL思维导图和代码分享

    本人SQL新手,五一期间自学了<SQL必知必会>一书,在此简要分享学习心得,若有差错,请各位大佬们多多指教呀! 本人的SQL学习计划是先根据<SQL必知必会>一书入门,了解SQ ...

  10. sql简介_SQL简介

    sql简介 Today, data is the basis of any business. The world of enterprise computing is the epitome of ...

最新文章

  1. C++调用Python实例
  2. Flutter实现动画卡片式Tab导航 | 掘金技术征文
  3. Jquery实现点击页面发送弹幕效果
  4. 七月算法--12月机器学习在线班-第七次课笔记—最大熵
  5. cookie和session原理
  6. 科普 | 微服务和软件技术栈
  7. python写小猪佩奇_python之小猪佩奇
  8. CUDA的global内存访问的问题
  9. 【在线集成开发环境】Eclipse Che简单上手体验
  10. C++新特性探究(七):初始化列表(Initialization List)
  11. 从html5的新特性定位安全问题
  12. 特斯拉线圈怎么用_无线快充居然是特斯拉发明的?不愧是发明家
  13. RapidMiner
  14. 51nod1534 棋子游戏
  15. 微博清理多个百万粉丝大号:打击违规账号要命中七寸
  16. 怎样卸载deepin系统_win10系统双系统下卸载deepin的详细技巧
  17. Lambda表达详细介绍、全的不能全了!!
  18. Linux虚拟主机与Windows虚拟主机之间有什么区别
  19. sci-ei求中啊啊啊
  20. Excel快捷的把列宽调整到合适的宽度

热门文章

  1. [转载] python查看的统计量_python 描述性统计_Python中的基本统计:描述性统计
  2. 《计算机网络 自顶向下方法》 第2章 应用层 Part1
  3. html前端通过canvas生成验证码
  4. 拼多多服务端实习生笔试-滑动窗口2018/4/3
  5. JS编写自己的富文本编辑器
  6. Python 快速部署安装所需模块
  7. java 改文件名的例子
  8. Java配置环境变量、方法和原因
  9. javax.crypto.BadPaddingException: Blocktype ...
  10. Django实战(10):单元测试