Group Functions Lab 6.

Slides:



Advertisements
Similar presentations
Using the Set Operators
Advertisements

Copyright  Oracle Corporation, All rights reserved. 4 Aggregating Data Using Group Functions.
1. Write an Excel formula in cell Survey
Database Programming Sections 5 & 6 – Group functions, COUNT, DISTINCT, NVL, GROUP BY, HAVING clauses, Subqueries.
AGGREGATE FUNCTIONS Prof. Sin-Min Lee Surya Bhagvat CS 157A – Fall 2005.
Aggregating Data Using Group Functions. Objectives After completing this lesson, you should be able to do the following: Identify the available group.
4 Copyright © 2004, Oracle. All rights reserved. Reporting Aggregated Data Using the Group Functions.
5 Copyright © Oracle Corporation, All rights reserved. Aggregating Data Using Group Functions.
Copyright  Oracle Corporation, All rights reserved. 5 Aggregating Data Using Group Functions.
1Eyad alshareef Enhanced Guide to Oracle 10g Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data.
GROUP FUNCTIONS. Objectives After completing this lesson, you should be able to do the following: Identify the available group functions Describe the.
Aggregating Data Using Group Functions. Objectives After completing this lesson, you should be able to do the following: Identify the available group.
5 Copyright © 2007, Oracle. All rights reserved. Reporting Aggregated Data Using the Group Functions.
5 Copyright © Oracle Corporation, All rights reserved. Aggregating Data Using Group Functions.
4 การใช้ SQL Functions. Copyright © 2007, Oracle. All rights reserved What Are Group Functions? Group functions operate on sets of rows to give.
Chapter 11 Group Functions
LECTURE 10.  Group functions operate on sets of rows to give one result per group.
Structured Query Language Part I Chapter Three CIS 218.
Enhancements to the GROUP BY Clause Fresher Learning Program January, 2012.
Database Programming Sections 5– GROUP BY, HAVING clauses, Rollup & Cube Operations, Grouping Set, Set Operations 11/2/10.
SQL/lesson 2/Slide 1 of 45 Retrieving Result Sets Objectives In this lesson, you will learn to: * Use wildcards * Use the IS NULL and IS NOT NULL keywords.
4 Copyright © 2004, Oracle. All rights reserved. Reporting Aggregated Data Using the Group Functions.
Copyright س Oracle Corporation, All rights reserved. 5 Aggregating Data Using Group Functions.
5 Copyright © Oracle Corporation, All rights reserved. Aggregating Data Using Group Functions.
Structured Query Language. Group Functions What are group functions ? Group Functions Group functions operate on sets of rows to give one result per group.
CN2180 MS SQL Server Kemtis Kunanuraksapong MSIS with Distinction, A+ MCTS, MCDST, MCP.
SQL-5 (Group By.. Having). Group By  Need: To apply the aggregate functions to subgroups of tuples in a relation, where the subgroups are based on some.
In this session, you will learn to: Use functions to customize the result set Summarize and group data Objectives.
Intermediate SQL: Aggregated Data, Joins and Set Operators.
IFS180 Intro. to Data Management Chapter 13 – Grouping Data.
Aggregating Data Using Group Functions. Objectives After completing this lesson, you should be able to do the following: –Identify the available group.
Aggregating Data Using Group Functions. What Are Group Functions? Group functions operate on sets of rows to give one result per group.
5-1 Copyright © 2004, Oracle. All rights reserved. DISPLAYING DATA FROM MULTIPLE TABLES OUTER JOIN.
Chapter 11 – Data Manipulation: Relational Algebra and SQL1 Unit 9: Data Manipulation: Relational Algebra and SQL IT238: Data Modeling and Database Design.
Reporting Aggregated Data Using the Group Functions
Using Subqueries to Solve Queries
In this session, you will learn to:
Writing Basic SQL SELECT Statements
Aggregating Data Using Group Functions
Enhanced Guide to Oracle 10g
SQL AGGREGATE FUNCTIONS
Subqueries Schedule: Timing Topic 25 minutes Lecture
The Database Exercises Fall, 2009.
Working with Tables: Join, Functions and Grouping
Chapter 5: Aggregate Functions and Grouping of Data
Aggregating Data Using Group Functions
SQL FUNDAMENTALS CDSE Days 2018.
(SQL) Aggregating Data Using Group Functions
Using the Set Operators
Aggregating Data Using Group Functions
SQL – Entire Select.
Chapter 4 Summary Query.
Aggregating Data Using Group Functions
Aggregating Data Using Group Functions
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall
SQL Subquery.
CS122 Using Relational Databases and SQL
Reporting Aggregated Data Using the Group Functions
Section 4 - Sorting/Functions
Subqueries Schedule: Timing Topic 25 minutes Lecture
Using Subqueries to Solve Queries
Reporting Aggregated Data Using the Group Functions
Using Subqueries to Solve Queries
Reporting Aggregated Data Using the Group Functions
Subqueries Schedule: Timing Topic 25 minutes Lecture
分组函数 Schedule: Timing Topic 35 minutes Lecture 40 minutes Practice
Aggregating Data Using Group Functions
Presentation transcript:

Group Functions Lab 6

Group Function SQL Server Group Functions operate on sets of rows to give one result per group, for example :

SQL SERVER common Group Function

SQL SERVER common Group Function

SQL SERVER Group Function And NULL In SQL Server, All Group functions ignore NULL values. In SQL Server You can use the ISNULL function to force group functions to include NULL values.

Write a query to display the average vacation hours of male and female employees in human resource.employee table

SQL server Group by Caluse So far, each group function described here has treated the table as one large group of data In most cases you need to divide the table into smaller groups One can use the SQL Server GROUP BY clause to divide the rows in a table into groups. Then you can use the group functions to retrieve summary information for each group.

Group by clause Syntax

Few guidelines for using group clause All columns in the SQL Server SELECT clause that are not group functions must be in the GROUP BY clause

Guidelines The SQL Server GROUP BY columns don’t have to be in the SQL Server SELECT clause

Guidelines You can list more than one column after the SQL Server GROUP BY clause

Guidelines Using the SQL Server WHERE clause, you can exclude rows before dividing them into groups

Guidelines You cannot use the SQL Server WHERE clause to restrict groups

Having clause The SQL Server HAVING clause allows filtering of aggregated results produced by the SQL Server GROUP BY clause.

LAB TASK 1 .Determine the validity of the following statements: (T/F) Group function works across many rows to produce one result Group function include null values The where clause restrict rows prior to inclusion in the group calculations

LAB TASK 2. Display the no of rows in the humanresource. Employee table and label the column as “total no of records”. 3. Display the number of values in middle name column including null values from person.person table. 4. Display the number of null values in middle name column of person.person table

LAB TASK 5. Display the highest, lowest, sum and average vacation hours of all employees. Label the columns Max, Min, Sum and average vacation hours of all the employees. 6. Display the min, max, sum, average vacation hours for each job title. 7. Write the query to display the number of people with the same job title

LAB TASK 8. Determine the research and development manager without listing them. Label the column no as research and development engineer. 9. Write a query that will display the difference between highest and lowest vacation hours and label it as column difference. 10. Display the design engineer number and vacation hours who have least no of vacation hours

LAB TASK 11. Display the gender and no of employees belong to each gender in humanresource.employee table. 12. Display the group name and no of departments in each group. Only for the group name which contain ‘AND’ in their name. 13. Display the group name and no of departments in each group. Only for the group name who have at least 2 departments

LAB TASK 14. Display the job title and lowest hire date for each job title. 15. Display the job title and lowest hire date for each job title. Only for the job title where the lowest hire date is greater than 2008-12- 16

LAB TASK 16. Display the job title and the average sick leave hours for each job title. 17. Display the job title and the average sick leave hours for each job title, only for job title of design engineer, tool designer and marketing specialist.

THE END