- 1
- 0
- 约1.6万字
- 约 28页
- 2018-07-31 发布于天津
- 举报
Les0使用分组函数来对数据进行聚集
五.使用分组函数来对数据进行聚集 目标 完成本节课的学习后,应当完成下面的目标: 识记常用的分组函数。 描述分组函数的用处。 使用GROUP BY 子句对元组进行分组 使用HAVING 子句来筛选分组 什么是分组函数? 分组函数对一组数据行进行操作,并对每个组得出一个结果. 分组函数的类型 AVG COUNT MAX MIN STDDEV SUM VARIANCE 使用分组函数 使用AVG和SUM 函数 对于数字类型的数据,可以使用 AVG和SUM 函数. 使用 MIN和MAX 函数 可以对许多类型的数据使用MIN和MAX函数. 使用 COUNT函数 COUNT(*) 返回查询出的总行数. 使用 COUNT函数 COUNT(expr) 返回expr值非空的行的数. 分组函数和空值 分组函数忽略了行中所有的空行. 分组函数和NVL函数的结合 NVL函数使得分组函数可以处理空值. 创建聚组数据 创建分组数据: GROUP BY 子句 将表中的数据行用GROUP BY语句分为几个组. 使用 GROUP BY子句 在SELECT语句中,没有使用分组函数的列必须在GROUP By子句中. 使用 GROUP BY子句 GROUP BY后面的列可以不出现在 SELECT链中. 根据多个列进行分组 在多个列上使用 GROUP BY 子句 分组函数的误用 在SELECT 语句中,任何不在聚组函数中出现的列,必须在 GROUP BY 子句中. 分组函数的误用 不能在 WHERE子句中对列做出限定. 使用 HAVING 子句来限定分组. 排除聚组结果 用 HAVING 子句排除分组结果 用 HAVING 子句来限定分组 行被分组了. 使用了分组函数. 符合 HAVING子句条件的组将被显示出来. 使用 HAVING 子句 使用 HAVING子句 分组函数的嵌套使用 显示最大的平均工资. 总结 子聚的顺序: WHERE 子句 GROUP BY 子句 HAVING 子句 Group Functions Unlike single-row functions, group functions operate on sets of rows to give one result per group. These sets may be the whole table or the table split into groups. Group Functions (continued) Each of the functions accepts an argument. The following table identifies the options that you can use in the syntax: Guidelines for Using Group Functions DISTINCT makes the function consider only nonduplicate values; ALL makes it consider every value including duplicates. The default is ALL and therefore does not need to be specified. The datatypes for the arguments may be CHAR, VARCHAR2, NUMBER, or DATE where expr is listed. All group functions except COUNT(*) ignore null values. To substitute a value for null values, use the NVL function. The Oracle Server implicitly sorts the result set in ascending order when using a GROUP BY clause. To override this default ordering, DESC can be used in an ORDER BY clause. Instructor Note Stress the use of DISTINCT and group functions ignoring null values. ALL is the default and is very rarely specified. Group Functions You can use AVG, SUM, MIN, and MAX functions against columns t
您可能关注的文档
最近下载
- (人教版2026新教材)数学二年级下册新教材解读课件.pptx
- 松下sj-mr220中文使用说明书.pdf VIP
- 融优学堂明式家具赏析(中国美术学院)章节测验答案.docx
- 2025年铁道统计公报 .pdf VIP
- 北汽新能源EU5维修手册OBC.pptx VIP
- ISO10292-1994建筑玻璃.多层玻璃稳态U值(热透过率)的计算.PDF VIP
- 北汽新能源EU5维修手册-电路图.pdf VIP
- TCNEA-核电工程班组建设评价指南及编制说明.pdf VIP
- 基层行低利率环境对金融增加值的影响分析.pdf VIP
- 2025-2026学年小学音乐鲁教版五四学制2024一年级下册-鲁教版(五四学制)(2024)教学设计合集.docx
原创力文档

文档评论(0)