mysql 字符串转数字后分组求和统计
2020-04-21 本文已影响0人
HaleyLiu
- 先看字符转数字有以下方法:
方法一:SELECT CAST('123' AS SIGNED);
方法二:SELECT CONVERT('123',SIGNED);
方法三:SELECT '123'+0;
- 然后分组求和统计:
SELECT
name,
sum(
CASE
WHEN age IS NULL THEN
'0'
ELSE
age + 0
END
) AS age_sum
FROM
user
GROUP BY
name