title: Subqueries and AVG() on a subtraction
body: <p>Working on a query to return the average time from when an employee begins his/her shift and then arrives at the first home (this DB assumes they are salesmen).</p>
  
  <p>What I have:</p>
  
  <pre><code>SELECT l.OFFICE_NAME, crew.EMPLOYEE_NAME, //avg(first arrival time)
  FROM LOCAL_OFFICE l, CREW_WORK_SCHEDULE crew,
  WHERE l.LOCAL_OFFICE_ID = crew1.LOCAL_OFFICE_ID
  </code></pre>
  
  <p>You can see the AVG() command is commented out, because I know the time that they arrive at work, and the time they get to the first house, and can find the value using this:</p>
  
  <pre><code>(SELECT MIN(c.ARRIVE)
   FROM ORDER_STATUS c
   WHERE c.USER_ID = crew.CREW_ID)
   -(SELECT START_TIME
   FROM CREW_SHIFT_CODES
   WHERE WORK_SHIFT_CODE = crew.WORK_SHIFT_CODE)
  </code></pre>
  
  <p>Would the best way be to simply put the above into the the AVG() parentheses? Just trying to learn the best methods to create queries. If you want more info on any of the tables, etc. just ask, but hopefully they're all named so you know what they're returning.</p>