Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
233 views
in Technique[技术] by (71.8m points)

How do I find the average of a count in MySQL?

I need to find the average of a count as described below, but when the code is executed, error 1111 is returned. I know I need a nested query to solve the issue, but I don't know how to format it.

SELECT COUNTRY.COUNTRY_NAME, CITY.CITY_NAME, COUNT(CUSTOMER.CITY_ID)
FROM COUNTRY
JOIN CITY
ON COUNTRY.ID = CITY.COUNTRY_ID
JOIN CUSTOMER
ON CITY.ID = CUSTOMER.CITY_ID
GROUP BY CITY.CITY_NAME
HAVING COUNT(CUSTOMER.CITY_ID) > AVG(COUNT(CUSTOMER.CITY_ID))
ORDER BY COUNTRY.COUNTRY_NAME ASC;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...