Answer To Exercises: Query Results Using Boolean Logic

  • Home
  • I
  • Answer To Exercises: Query Results Using Boolean Logic

Question #1

Find all single female employees

SELECT NationalIDNumber,
       MaritalStatus,
       Gender
FROM   HumanResources.Employee
WHERE  MaritalStatus = 'S'
       AND Gender = 'F'

Question #2

Find all employees that have 40 to 80 hours of vacation time.

SELECT NationalIDNumber,
       MaritalStatus,
       Gender,
       VacationHours
  FROM HumanResources.Employee
 WHERE VacationHours >= 40
       AND VacationHours <= 80

Question #3

Find all employees that have 40 to 80 hours of vacation time or 40 to 80 hours of sick time,  and are male.

SELECT NationalIDNumber,
       MaritalStatus,
       Gender,
       VacationHours,
       SickLeaveHours
FROM   HumanResources.Employee
WHERE  (   (VacationHours >= 40 AND VacationHours <= 80)
        OR (SickLeaveHours >= 40 AND SickLeaveHours <= 80)
       )
       AND Gender = 'M'

Notice on this last example we used parenthesis to ensure the order of evaluating the clauses was correct.

>