@janders23,
If you have a query like
SELECT a.dep_month,
a.dep_day_of_week,
AVG(a.flight_count) AS average_flights
FROM (
SELECT dep_month,
dep_day_of_week,
dep_date,
COUNT(*) AS flight_count
FROM flights
GROUP BY 1,2,3
) a
you have to visualize it like
[ outer-query ]
from
[inner-query] as a
With the inner-query you create a =virtual-table=
in the [outer-query]
you can refer to this [inner-query] as a ( question-2 is answered )
###=============================================================
A =table= consists of 1 or more ROW
's
the DBMS keeps track of those ROW
's by giving each =row= a unique ROW-ID
+--------+-------------------
| ROW-ID | ........
+--------+-------------------
Each ROW
consists of the ROW-ID
and 1 or more **COL
**umns
+--------+----------------------------
| ROW-ID | COL | COL | COL | .......
+--------+----------------------------
In your [inner-query] you use
SELECT dep_month,
dep_day_of_week,
dep_date,
COUNT(*) AS flight_count
FROM flights
the DBMS will create a virtual =table=
collecting DATA out of the FLIGHTS =table=
using ALL ROW
's (as you are not using a WHERE clause )
from each ROW
picking up data
from the COL
umns
dep_month ( for the DBMS it is (1) for your =display= it is as dep_month )
dep_day_of_week ( for the DBMS it is (2) for your =display= it is as dep_day_of_week )_
dep_date ( for the DBMS it is (3) for your =display= it is as dep_date )
then with _COUNT(*)
_ you create a virtual COL
umn
which is a counter, counting every selected _ROW
_
displaying it as an =integer= and with your as flight_count
the COL would be displayed as flight_count
for the DBMS it would be (4)
for-display DBMS
SELECT dep_month, (1)
dep_day_of_week, (2)
dep_date, (3)
COUNT(*) AS flight_count (4)
FROM flights