1
A question about Mysql asks the result to exit in this answer format.
When finishing my solution through a consultation made on Mysql, find the following problem.
Below is a first example solution of my query that Works
SELECT CONCAT('There are a total of ' , COUNT(name),' ', occupation ) FROM OCCUPATIONS GROUP BY occupation ORDER BY COUNT(name) ASC ;
Below is a second solution example of my query that Doesn’t Work
SELECT CONCAT('There are a total of ' , COUNT(name) AS Numb,' ', occupation ) FROM OCCUPATIONS GROUP BY occupation ORDER BY Numb ASC ;`
The problem at issue is that I would like to rename the COUNT(name)
for numb
through a 'alias' or a pseudo name, but I’m faced with this mistake.
ERROR 1583 (42000) at line 3: Incorrect parameters in the call to native function 'concat'
It would be possible to circumvent this problem, that is, it is possible to use pseudo names within the function CONCAT
?
Whenever I use some aggregation function I usually give names to them, in this case it is not to repeat the "COUNT(name)" in the part of GROUP BY.
– Jonathas B. C.
In this case the solution is to use a sub-query to calculate the total, after which you can use the alias in both SELECT and GROUP BY
– bruno