题解 | #统计每种性别的人数#
统计每种性别的人数
https://www.nowcoder.com/practice/f04189f92f8d4f6fa0f383d413af7cb8
使用substring_index函数可以按特定字符串截取源字符串。
substring_index(FIELD, sep, n)可以将字段FIELD按照sep分隔:
(1).当n大于0时取第n个分隔符(n从1开始)左边的全部内容;
(2).当n小于0时取倒数第n个分隔符(n从-1开始)右边的全部内容;
因此,本题可以直接用substring_index(profile, ',', -1)取出性别。 附:substring_index函数解析
select substring_index(profile, ",", -1) as gender, count(device_id) as number from user_submit group by gender
查看11道真题和解析
