mysql|mysql 字符串转数字后分组求和统计

  1. 先看字符转数字有以下方法:
方法一:SELECT CAST('123' AS SIGNED); 方法二:SELECT CONVERT('123',SIGNED); 方法三:SELECT '123'+0;

  1. 然后分组求和统计:
SELECT name, sum( CASE WHEN age IS NULL THEN '0' ELSE age + 0 END ) AS age_sum FROM user GROUP BY name

    推荐阅读