title: Using avg() function in SQL query returns only one row?
body: <p>I have this SQL query:</p>
  
  <pre><code>SELECT DISTINCT aname, avg(salary) 
  FROM aircraft, certified, employees 
  WHERE cruisingrange &gt; 1000 AND ((certified.eid = employees.eid) = (aircraft.aid = certified.aid));
  </code></pre>
  
  <p>In one column, I am trying to display the aircraft names (aname) of all aircraft with cruising ranges over 1000 miles (cruisingrange > 1000). In the other column, I am trying to display the average salary (avg(salary)) of certified pilots (certified.eid = employees.eid) who are certified to fly that aircraft in particular (entire conditional after AND). However, it's conglomerating all the salaries into a single value and returning that, therefore I am only given a table with two columns and one row instead many rows (it only displays one aircraft name as well). </p>
  
  <p>These SQL queries separately work just fine, though:</p>
  
  <pre><code>SELECT aname 
  FROM aircraft 
  WHERE cruisingrange &gt; 1000;
  
  SELECT avg(salary)
  FROM employees, certified
  WHERE employees.eid = certified.eid;
  
  SELECT DISTINCT aname
  FROM aircraft, certified
  WHERE certified.aid = aircraft.aid;
  </code></pre>
  
  <p>How do I write a query that does what I'm supposed to do? I just started self-teaching SQL today so sorry if the answer is pretty obvious. Any suggestions are appreciated.</p>