I have this SQL query:
SELECT DISTINCT aname, avg(salary)
FROM aircraft, certified, employees
WHERE cruisingrange > 1000 AND ((certified.eid = employees.eid) = (aircraft.aid = certified.aid));
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).
These SQL queries separately work just fine, though:
SELECT aname
FROM aircraft
WHERE cruisingrange > 1000;
SELECT avg(salary)
FROM employees, certified
WHERE employees.eid = certified.eid;
SELECT DISTINCT aname
FROM aircraft, certified
WHERE certified.aid = aircraft.aid;
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.