select 
    substring_index(substring_index(profile,',',-1),',',1) as gender,
    count(device_id) as number
from
    user_submit
group by
    substring_index(substring_index(profile,',',-1),',',1)
  1. select部分:substring_index(substring_index(profile,',',-1),',',1) as gender:先使用substring_index(profile,',',-1)从profile字段中以逗号为分隔符,提取最后一个分隔后的子字符串;再用外层的substring_index以逗号为分隔符,提取这一子字符串中的第一个部分,将其命名为gender,即提取出性别信息。count(device_id) as number:统计device_id的数量,并命名为number,表示每种性别的用户数量。
  2. from user_submit:指定从user_submit表中获取数据。
  3. group by部分:substring_index(substring_index(profile,',',-1),',',1)按照提取出的性别信息进行分组,以便分别统计不同性别的用户数量。