SQL: HAVING Clause
The HAVING clause is used in combination with the GROUP BY clause. It can be used in a SELECT statement to filter the records that a GROUP BY returns.
译:HAVING子句是与GROUP BY子句联合使用。能够用于SELECT语句中用于筛选由GROUP BY返回的结果。
The syntax for the HAVING clause is:
SELECT column1, column2, ... column_n, aggregate_function (expression)
FROM tables
WHERE predicates
GROUP BY column1, column2, ... column_n
HAVING condition1 ... condition_n;
aggregate_functioncan be a function such as SUM, COUNT, MIN, or MAX.
译:aggregate_function可以是SUM, COUNT, MIN, or MAX函数。
Example using the SUM function
For example, you could also use the SUM function to return the name of the department and the total sales (in the associated department). The HAVING clause will filter the results so that only departments with sales greater than $1000 will be returned.
译:例如,你可以使用SUN函数返回以department为分组的总销售。HAVING子句就会选择销售大于$1000的结果返回。
SELECT department, SUM(sales) as "Total sales"
FROM order_details
GROUP BY department
HAVING SUM(sales) > 1000;
Example using the COUNT function
For example, you could use the COUNT function to return the name of the department and the number of employees (in the associated department) that make over $25,000 / year. The HAVING clause will filter the results so that only departments with at least 25 employees will be returned.
译:例如,你可以使用COUNT函数返回以部门为单位的,工资超过$25000/年的员工人数。HAVING子句将返回部门员工数满足该条件25人以上的结果集。
SELECT department, COUNT(*) as "Number of employees"
FROM employees
WHERE salary > 25000
GROUP BY department
HAVING COUNT(*) > 10;
Example using the MIN function
For example, you could also use the MIN function to return the name of each department and the minimum salary in the department. The HAVING clause will return only those departments where the starting salary is $35,000.
译:返回起始工资为$35,000的最低工资的结果集。
SELECT department, MIN(salary) as "Lowest salary"
FROM employees
GROUP BY department
HAVING MIN(salary) = 35000;
Example using the MAX function
For example, you could also use the MAX function to return the name of each department and the maximum salary in the department. The HAVING clause will return only those departments whose maximum salary is less than $50,000.
译:返回最高工资为50000的最高工资的结果集。
SELECT department, MAX(salary) as "Highest salary"
FROM employees
GROUP BY department
HAVING MAX(salary) < 50000;

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

SQL HAVING Clause相关推荐

  1. oracle sql within,Oracle SQL Model Clause

    参考官方文档,学习了一下Oracle SQL Model语法. 摘自Pro Oracle SQL: With the MODEL clause, you build matrixes (or a mo ...

  2. python直接执行*.sql_Python Django 之 直接执行自定义SQL语句(一)

    三.raw()方法 1.raw()用法 The raw() manager method can be used to perform raw SQL queries that return mode ...

  3. 使用flink Table Sql api来构建批量和流式应用(2)Table API概述

    从flink的官方文档,我们知道flink的编程模型分为四层,sql层是最高层的api,Table api是中间层,DataStream/DataSet Api 是核心,stateful Stream ...

  4. sql limit子句_SQL子句解释的位置:之间,之间,类似和其他示例

    sql limit子句 什么是SQL Where子句? (What is a SQL Where Clause?) WHERE子句(和/或IN , BETWEEN和LIKE ) (The WHERE ...

  5. sql crud_SQL Server中的CRUD操作

    sql crud CRUD operations are foundation operations every database developer and administrator needs ...

  6. sql中join类型_SQL Join类型概述和教程

    sql中join类型 This article will provide an overview of the SQL Join and cover all of the SQL join types ...

  7. sql limit 子句_SQL Join子句介绍和概述

    sql limit 子句 The SQL Join clause is one of the major components of the Select statement, which is us ...

  8. 利用T-SQL动态定义重复SQL Server数据库表行

    介绍 (Introduction) Lever T-SQL to handle duplicate rows in SQL Server database tables article highlig ...

  9. sql 逻辑运算符_SQL Like逻辑运算符介绍和概述

    sql 逻辑运算符 The SQL Like is a logical operator that is used to determine whether a specific character ...

最新文章

  1. 《庆余年》,腾讯视频、爱奇艺为“互联网黑产”背锅的一出戏
  2. Linux errno 列表
  3. edxp显示未安装_如何在 Centos 8 / RHEL 8 上安装和配置 VNC 服务器
  4. 关于求XXX.class.getResource(xxx).getPath()的用法
  5. [轉]VS 2010 通过 Architecture创建UML类图设计
  6. day08—css布局解决方案之多列布局
  7. 每秒处理10万高并发订单的乐视集团支付系统架构分享
  8. java Selenium 发送126邮件 解决element not visible
  9. java 求球体表面积_java设计:计算圆的面积和球体的体积,在一个类中用两种方法实现...
  10. 液滴模板水凝胶的温度控制形状变化(定制PNIPA/膨润土复合水凝胶/聚乙烯醇/魔芋胶复合凝胶/海藻酸钠(SA)/氧化石墨烯(GO)复合水凝胶/壳聚糖(CS)-g-PAM/氧化石墨烯(GO)复合水凝胶)
  11. python学习笔记---函数【廖雪峰】
  12. 小学生python编程写游戏_小学生开始学Python,开发AI的首选编程语言:推荐一波Python书单...
  13. 【人工智能】1.问题求解:启发式搜索算法
  14. 一天测血压的最佳时间_一天中什么时间测量血压最准?心血管医生告诉您最佳时间...
  15. 阿西莫夫:编造幻想与使之跟事实融为一体是两件事
  16. SpringBoot - 阿里云视频点播的简单使用
  17. HTML5+CSS3的学习(五)
  18. yocto 安装toolchain
  19. 解决Windows下移动硬盘无法弹出的问题:\$Extend\$RmMetadata\$TxfLog\$TxfLog.blf
  20. 第二章 Roboguide安装及注册步骤详解

热门文章

  1. 跟我读论文丨ACL2021 NER 模块化交互网络用于命名实体识别
  2. 你真的懂语音特征吗?
  3. “3+3”看华为云FusionInsight如何引领“数据新基建”持续发展
  4. 【华为云技术分享】探索软件复杂性简洁之道
  5. 华为云推出新冠肺炎AI辅助诊断服务,CT量化结果秒级输出
  6. python 最优化算法库_哈工大硕士生用?Python 实现了 11 种经典数据降维算法,源代码库已开放...
  7. td外边加div为啥不隐藏_过年炸油饼注意了,秘制配方比例教给你,柔软不吸油,放凉了不硬...
  8. python实现微信小游戏打飞机代码
  9. python获取select选中的值_python – 使用flask从select标签获取值
  10. rx java定时循环_Rxjava定时器异常循环