I have a SQL statement similar to this:
SELECT COUNT(*) AS foo, SUM(foo) AS foo_sum FROM bar
But MySQL doesn’t allow this because foo is an alias. Does anyone have an idea of how this could be accomplished in SQL?
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.
No, you can’t use an alias in the select-list or a WHERE clause. You can only use the alias in a GROUP BY, HAVING, or ORDER BY.
You can also use aliases defined in a subquery: