Home > Articles > Data > SQL

  • Print
  • + Share This
This chapter is from the book

Workshop

The following workshop is composed of a series of quiz questions and practical exercises. The quiz questions are designed to test your overall understanding of the current material. The practical exercises are intended to afford you the opportunity to apply the concepts discussed during the current hour, as well as build upon the knowledge acquired in previous hours of study. Please take time to complete the quiz questions and exercises before continuing. Refer to Appendix C, “Answers to Quizzes and Exercises,” for answers.

Quiz

  1. True or false: The AVG function returns an average of all rows from a SELECT column, including any NULL values.
  2. True or false: The SUM function adds column totals.
  3. True or false: The COUNT(*) function counts all rows in a table.
  4. True or false: The COUNT([column name]) function counts NULL values.
  5. Will the following SELECT statements work? If not, what fixes the statements?

    1. SELECT COUNT *
      FROM EMPLOYEES;
    2. SELECT COUNT(EMPLOYEEID), SALARY
      FROM EMPLOYEES;
    3. SELECT MIN(PAYRATE), MAX(SALARY)
      FROM EMPLOYEES
      WHERE SALARY > 50000;
    4. SELECT COUNT(DISTINCT EMPLOYEEID) FROM EMPLOYEES;
    5. SELECT AVG(LASTNAME) FROM EMPLOYEES;
    6. SELECT AVG(CAST(ZIP AS INT)) FROM EMPLOYEES;

Exercises

  1. Use the EMPLOYEES table to construct SQL statements to solve the following exercises:

    1. What is the average salary?
    2. What is the maximum pay rate for hourly employees?
    3. What are the total salaries?
    4. What is the minimum pay rate?
    5. How many rows are in the table?
  2. Write a query to determine how many employees are in the company whose last names begin with a G.
  3. Write a query to determine the minimum and maximum salary and pay rates per city for employees.
  4. Write two sets of queries to find the first employee name and last employee name when they are listed in alphabetical order.
  5. Write a query to perform an AVG function on the employee names. Does the statement work? Determine why it is that you got that result.
  6. Write a query to display the average value of employees’ salaries that takes NULL values into account. Hint: You won’t be using the AVG function.
  • + Share This
  • 🔖 Save To Your Account