UNION ALL Subqueries


#1

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?


#2

This is the solution that I have:

select id, avg(a.sale_price) from (
select id, sale_price from order_items
union all
select id, sale_price from order_items_historic) as a
Group By 1;


#3

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