Sams Teach Yourself SQL in 24 Hours

Sams Teach Yourself SQL in 24 Hours

By Ron Plew and Ryan Stephens

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: Both conditions when using the OR operator must be TRUE.

  2. True or false: All specified values must match when using the IN operator.

  3. True or false: The AND operator can be used in the SELECT and the WHERE clauses.

  4. What, if anything, is wrong with the following SELECT statements?

    1. SELECT SALARY 
      FROM EMPLOYEE_PAY_TBL
      WHERE SALARY BETWEEN 20000, 30000
      
    2. SELECT SALARY + DATE_HIRE 
      FROM EMPLOYEE_PAY_TBL
      
    3. SELECT SALARY, BONUS 
      FROM EMPLOYEE_PAY_TBL
      WHERE DATE_HIRE BETWEEN 1999-09-22
      AND 1999-11-23
      AND POSITION = 'SALES'
      OR POSITION = 'MARKETING'
      AND EMPLOYEE_ID LIKE '%55%
      

Exercises

  1. Using the following CUSTOMER_TBL:

    
                   DESCRIBE CUSTOMER_TBL; 
    
     Name                            Null?    Type
    -------------------------------- -------- ------------
     CUST_ID                         NOT NULL VARCHAR (10)
     CUST_NAME                       NOT NULL VARCHAR (30)
     CUST_ADDRESS                    NOT NULL VARCHAR (20)
     CUST_CITY                       NOT NULL VARCHAR (12)
     CUST_STATE                      NOT NULL VARCHAR(2)
     CUST_ZIP                        NOT NULL VARCHAR(5)
     CUST_PHONE                               VARCHAR (10)
     CUST_FAX                                 VARCHAR(10)
    

    Write a SELECT statement that returns customer IDs and customer names (alpha order) for customers who live in Indiana, Ohio, Michigan, and Illinois, and whose names begin with the letters A or B.

  2. Using the following PRODUCTS_TBL:

    
                   DESCRIBE PRODUCTS_TBL 
    
    Name                            Null?    Type
    ------------------------------- ---------------------
    PROD_ID                         NOT NULL VARCHAR (10)
    PROD_DESC                       NOT NULL VARCHAR (25)
    COST                            NOT NULL DECIMAL(6,2)
    

    Write a SELECT statement that returns the product ID, PROD_DESC, and the product cost. Limit the product cost to range from $1.00 and $12.50.

  3. Assuming that you used the BETWEEN operator in exercise 2 above, rewrite your SQL statement to achieve the same results using different operators. If you did not use the BETWEEN operator, then do so now.

  4. Write a SELECT statement that returns products that are either less than 1.00 or greater than 12.50. There are two ways to achieve the same results.

  5. Write a SELECT statement that returns the following information from PRODUCTS_TBL: product description, product cost, and 5% sales tax for each product. List the products in order from most to least expensive.

  6. Write a SELECT statement that returns the following information from PRODUCTS_TBL: product description, product cost, and 5% sales tax for each product, and total cost with sales tax. List the products in order from most to least expensive. There are two ways to achieve the same results. Try both.

Share ThisShare This

Informit Network