简体   繁体   中英

MySQL - Error Code 1630 "FUNCTION does not exist."

`

SELECT month(orderdate), category , sales * 100 / total_sales as pct_total_sales
FROM
(
    SELECT a.month(orderdate), a.category, a.sales, sum(b.sales) as total_sales
    FROM superstore a
    JOIN superstore b on a.month(orderdate) = b.month(orderdate)
        and b.category in ('technology', 'furniture')
        WHERE a.category in ('technology', 'furniture')
GROUP BY 1,2,3
) aa

`

"Error Code: 1630. FUNCTION a.month does not exist."

Trying to self-jjoin, MySQL assumes "a.month()" as a funcion. How can I fix this error?

If you want to express the month (orderdate) in the subquery, you need to define an alias in the subquery, otherwise it will cause ambiguous definitions. There are a few issues with the provided SQL query: SELECT month(orderdate) as month , category, sales * 100 / total_sales as pct_total_sales FROM ( SELECT a.month(orderdate) , a.category, a.sales, sum(b.sales) as total_sales FROM superstore a JOIN superstore b on MONTH(a.orderdate) = Month(b.orderdate) and b.category in ('technology', 'furniture') WHERE a.category in ('technology', 'furniture') GROUP BY 1,2,3 ) aa

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM