Table transformation errors

Using the same pattern, utilize a subquery to find the average sale price over both order_items and order_items_historic tables.

My code is:
select id, avg(sale_price) from (
select id, sale_price from order_items
union all
select id, sale_price from order_items_historic) as a;

the error is:
Select the average sale price avg(a.sale_price) for each item id for both the order_items and order_items_historic tables.

I am confused about what’s wrong. Can anyone help me with that?

The above may be replaced with,

group by 1;

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