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