title: Average of one column based on distinct values and group by of other columns
body: <p>Here is the SQL, I am using. But the average is not averaging on the distinct job numbers, it is using them all. </p>
  
  <p>I would like to get the average work time and total number of unique jobs, by customer. The average time has to be based on unique job numbers only.</p>
  
  <pre><code>SELECT CUSTOMER, COUNT(DISTINCT JOB_NO) AS JOB_COUNT, AVG(WORK_TIME) AS WT 
  FROM CYCLE_TIME 
  GROUP BY CUSTOMER 
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Charles, I used your first query and tested it with one customer. I get 5 jobs for the customer with the following WT values. <code>28.95, 24.72, 2.56, 15.14, 8.94</code>. That's an average of <code>16.06</code>.</p>
  
  <p>If I use the following query and only group by customer, the average (WT) ends up as 22.39. I'm not sure what's happening there.</p>
  
  <pre><code> SELECT CUSTOMER, JOB_NO, AVG(WORK_TIME) AS WT 
   FROM CYCLE_TIME 
   WHERE CUSTOMER='customer_a'
   GROUP BY CUSTOMER
  </code></pre>