- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
The GROUP BY Clause You can use the GROUP BY clause to divide the rows in a table into groups. You can then use the group functions to return summary information for each group. In the syntax: group_by_expression specifies columns whose values determine the basis for grouping rows Guidelines If you include a group function in a SELECT clause, you cannot select individual results as well, unless the individual column appears in the GROUP BY clause. You receive an error message if you fail to include the column list in the GROUP BY clause. Using a WHERE clause, you can exclude rows before dividing them into groups. You must include the columns in the GROUP BY clause. You cannot use a column alias in the GROUP BY clause. By default, rows are sorted by ascending order of the columns included in the GROUP BY list. You can override this by using the ORDER BY clause. The GROUP BY Clause (continued) When using the GROUP BY clause, make sure that all columns in the SELECT list that are not group functions are included in the GROUP BY clause. The example on the slide displays the department number and the average salary for each department. Here is how this SELECT statement, containing a GROUP BY clause, is evaluated: The SELECT clause specifies the columns to be retrieved: Department number column in the EMPLOYEES table The average of all the salaries in the group you specified in the GROUP BY clause The FROM clause specifies the tables that the database must access: the EMPLOYEES table. The WHERE clause specifies the rows to be retrieved. Since there is no WHERE clause, all rows are retrieved by default. The GROUP BY clause specifies how the rows should be grouped. The rows are being grouped by department number, so the AVG function that is being applied to the salary column will calculate the average salary for each department. Instructor Note Group results are sorted implicitly, on the grouping column. You can use ORDER BY to specify a different sort order,
您可能关注的文档
最近下载
- 信息系统等保安全方案.doc VIP
- 兴业银行信息技术专员岗位笔试选择题附笔试高分技巧.docx VIP
- 化工设计概论与化工制图课件第四章化工设备常用零部件简介.pptx VIP
- 高等教育5化工制图cad化工设备图中焊缝结构的表达.pptx VIP
- 化工设计概论与化工制图课件第七章车间布置设计.pptx VIP
- 新概念英语入门级6-10单元测试卷.pdf VIP
- 化工设计概论与化工制图课件第八章管道设计.pptx VIP
- 化工设计概论与化工制图课件第十章管道布置图.pptx VIP
- 化工制图cad8管道布置图.pptx VIP
- 统编版语文一年级下册2吃水不忘挖井人 课件(共54张PPT).pptx VIP
文档评论(0)