I kept getting error in SQL table transformation exercise IV


#1


Using a subquery, find the average total distance flown by day of week and month.

Be sure to alias the outer query as average_distance and the inner query as flight_distance.



select a.dep_month,
       a.dep_day_of_week,
       avg(a.flight_distance) as average_distance
from (
      select dep_month,
             dep_day_of_week,
             dep_date,
             distance as flight_distance
      from flihgts
      group by 1,2,3
  ) a
  group by 1,2
  order by 1,2;


Can anyone tell me what's wrong with my query? Thank you so much!


#2

You must replace this line --> distance as flight_distance

for this other one -->SUM(distance) AS flight_distance


#3

I tried that but there is still an error and could let me pass.
Error: " Use the select statement to view the table".


#4

This is the problem

select a.dep_month,
a.dep_day_of_week,
avg(a.flight_distance) as average_distance
from (
select dep_month,
dep_day_of_week,
dep_date,
distance as flight_distance
from flihgts <--.this "FROM" syntax is misspelled! --> is FLIGHTS not FLIHGTS
group by 1,2,3
) a
group by 1,2
order by 1,2;


#5

OMG!!! I am so stupid!
Thanks very much!


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.