What is wrong?


#1

Hi,
anyone to get a help?

The instruction:

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 AVG(a.sale_price) FROM (
SELECT id,sale_price FROM order_items
UNION ALL
SELECT id,sale_price FROM order_items_historic)
as a;

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

I don't understand what is wrong with this.
Thank you for your time and help.


#2

Hi miro19. I was having the same problem as you. It was fixed by adding

GROUP BY id
ORDER BY id;

at the end. I also changed my first line to,

SELECT id, AVG(a.sale_price) FROM (

Hope this works for you!


#3

Hi,
Thank you for your help. It's working now.


#4

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