Is is not possible to average the results from a subquery?
Here’s the query I’m fighting with:
SELECT AVG(
SELECT SUM(`retail_subtotal`)
FROM `order`
WHERE `status` IN('O')
GROUP BY `lead_id`
);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Actually, an easier way to phrase the query is without a subquery:
(This assumes lead_id is never NULL.)
Your original query had a problem not only because of the subquery in the avg(), but also because the subquery returned multiple rows.