Download presentation
Presentation is loading. Please wait.
1
Group Functions Lab 6
2
Group Function SQL Server Group Functions operate on sets of rows to give one result per group, for example :
3
SQL SERVER common Group Function
4
SQL SERVER common Group Function
5
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.
6
Write a query to display the average vacation hours of male and female employees in human resource.employee table
7
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.
8
Group by clause Syntax
9
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
10
Guidelines The SQL Server GROUP BY columns don’t have to be in the SQL Server SELECT clause
11
Guidelines You can list more than one column after the SQL Server GROUP BY clause
12
Guidelines Using the SQL Server WHERE clause, you can exclude rows before dividing them into groups
13
Guidelines You cannot use the SQL Server WHERE clause to restrict groups
14
Having clause The SQL Server HAVING clause allows filtering of aggregated results produced by the SQL Server GROUP BY clause.
15
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
16
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
17
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
18
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
19
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
20
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
21
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.
22
THE END
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.