Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 1. Group functions work across many rows to produce one result per group.
- -- TRUE
- -- 2. Group functions include nulls in calculations.
- -- TRUE
- -- 3. The WHERE clause restricts rows prior to inclusion in a group calculation.
- -- TRUE
- /* 4. Display the highest, lowest, sum, and average sa
- lary of all employees. Label the columns Maximum, M
- inimum,
- Sum, and Average, respectively. Round your results
- to the nearest whole number. */
- SELECT
- ROUND(MAX(salary),0) "Maximum",
- ROUND(MIN(salary),0) "Minimum",
- ROUND(SUM(salary),0) "Sum",
- ROUND(AVG(salary),0) "Average"
- FROM
- employees;
- /* 6. Write a query to display the number of people wi
- th the same job. */
- SELECT
- job_id, COUNT(employee_id) "Empl count"
- FROM
- employees
- GROUP BY
- job_id;
- /* 8. Write a query that displays the difference betwe
- en the highest and lowest salaries. Label the colum n DIFFERENCE. */
- SELECT
- ROUND(MAX(salary)-MIN(salary),0) "DIFFERENCE"
- FROM
- employees;
- /* 9. Display the manager number and the salary of the
- lowest paid employee for that manager. Exclude any one whose
- manager is not known. Exclude any groups where the
- minimum salary is less than $6,000. Sort the output
- in descending order of salary. */
- SELECT
- manager_id, MIN(salary)
- FROM
- employees
- WHERE
- manager_id IS NOT NULL
- GROUP BY
- manager_id
- HAVING
- MIN(salary) >= 6000
- ORDER BY
- MIN(salary) DESC;
- /* 13. Displays the number of employees in department 50*/
- SELECT
- COUNT(*)
- FROM
- employees
- WHERE department_id = 50;
- /* 16. Display the number of distinct department values in the EMPLOYEES table. */
- SELECT
- COUNT(DISTINCT department_id)
- FROM
- employees;
- /* 19. Display of average salaries of those departments
- that have an average salary greater than $8,000 */
- SELECT
- department_id, ROUND(AVG(salary),0)
- FROM
- employees
- GROUP BY
- department_id
- HAVING
- AVG(salary) > 8000;
Advertisement
Add Comment
Please, Sign In to add comment