3. Union ALL wired error message


#1

Error message

 Select the average sale price  for each item uid=1000(ccuser) gid=1000(ccuser) groups=1000(ccuser) for both the  and  tables.

Code:

SELECT AVG(sale_price) FROM (
    SELECT sale_price FROM order_items
    UNION ALL
    SELECT sale_price FROM order_items_historic);

#2

Getting the same error here. Strange.

I revised my code to:
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;

And the error went away. I guess it wants the averages grouped by ID?


#3

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