If I want to make a sum of a specific numeric column in MySQL, I do
SELECT SUM(MyColumn) FROM MyTable WHERE 1;
This returns for example num
As FreshPrinceOfSO suggested in the comments below my question, MySQL server doesn't handle casts to varchar
.
So even though the query
SELECT CONCAT('Sum is: ',CAST(SUM(MyColumn) AS varchar(20))) FROM MyTable WHERE 1;
results in syntax error, casting to char
instead works just fine:
SELECT CONCAT('Sum is: ',CAST(SUM(MyColumn) AS char(20))) FROM MyTable WHERE 1;