I kept getting error in SQL table transformation exercise IV

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
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.

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>

<In this course, it often helps to include a screenshot of your whole web browser – that lets everyone see what you see. If you wish to include a screenshot, add it below this line.>

<If you wish to copy/paste in your code, you can use this next section. This will allow others to copy/paste your code for testing – something that they won’t be able to do with just a screenshot.>

```

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;

<do not remove the three backticks above>
Can anyone tell me what's wrong with my query? Thank you so much!

You must replace this line --> distance as flight_distance

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

1 Like

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

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;

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

1 Like

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