Chapter 6 Application Flashcards
Prepare a summary query that uses COUNT(*) on Employee, and AVG(), SUM(), MIN(), and MAX() on the Employee.salary column.
select COUNT(*) as Number_of_Employees, round(AVG(salary),2) as avg_salary,SUM(salary) as Total_Salary, MAX(salary) as Highest_Salary, MIN(salary) as Lowest_Salary from employee;
Code a summary query that works on a non-numeric column such as hiredate. Explain what the result indicates.
Select Min(hireDate) as Earliest_HireDate from employee;
Result shows the first person hired in the list of employees.
Write a summary query on Employee using the DISTINCT keyword when counting the different jobs supervised by manager 7698 and also computes average salary for that manager’s employees.
select count(DISTINCT empno) as Number_of_Employees, round(avg(salary),2) as Avg_Salary from employee where manager = 7698;
Prepare a summary query that calculates the maximum salary by department.
select deptno, max(salary) from employee group by deptno;
Code a summary query that calculates average salary for those departments that have three or more employees.
select deptno, round(avg(salary),2) as Avg_Salary from employee group by deptno having count(deptno) > 3;
Write a select statement to produce a summary query with a compound condition in the having clause to count the number of employees in department 20 with a job in the list (‘ANALYST’, ‘CLERK’).
select count(*) as NumEmpInDept, job, deptno from employee where deptno = 20 group by job having job = ‘clerk’ or job = ‘analyst’;